Loading View only (No Layout) - Yii Framework

Asked

Viewed 579 times

1

I’m customizing a website on Yii. And I’m having doubts about how to access a file that’s inside the directory protected/. I’m using a javascript function to load only the view of admin, but I think he’s protecting (as expected). He gives the load in the content, but does not load the desired file :'(

HTML:

<div class="menu">
    <ul>
        <li><a class="nome-menu" data-nome="usuario" href="#">Usuário</a></li>
    </ul>
</div>

<div class="content">
    <!--carregar a view de admin aqui!!!
</div>

Javascript:

$(".nome-menu").click(function (e) {
    $(".content").load('/MyProject/protected/views/usuario/admin.php');
});

Mockup:

inserir a descrição da imagem aqui

2 answers

2

I have succeeded with two amendments:

1º) change the address of load for load('/MyProject/index.php?r=usuario/admin'). where he accesses the UsuarioController looking for the function actionAdmin().

2º) In function actionAdmin() who is in the Controller, I needed to set false for the layout rendering as follows: $this->layout = false; not to load another layout inside the Content.

0

Utilize Yii::app()->request->isAjaxRequest to know if the request was ajax, and if so use renderPartial(). This way you can access the url '/Myproject/index.php? r=user/admin' either directly from the browser or via a load(). Both cases are covered.

public function actionAdmin()
{
    if (Yii::app()->request->isAjaxRequest)
    {
        // Renderizará a view SEM o layout.
        $this->renderPartial('admin');
    }
    else
    {
       // Renderizará a view COM o layout.
       $this->render('admin');
    }        
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.