Loading View only (without Layout) - Yii Framework

1

I'm customizing a website at Yii . And I'm wondering how do I access a file that is within the protected/ directory. I'm using a javascript function to only load view of admin , but I think it's protecting (as expected). It gives load in 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:

    
asked by anonymous 04.04.2014 / 20:09

2 answers

2

I was able to succeed with two changes:

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

2) In the actionAdmin() function that is in Controller , I had to set false to render the layout as follows: $this->layout = false; so it does not load another layout within Content .

    
04.04.2014 / 21:37
0

Use 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=usuario/admin' either directly through the browser or through 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');
    }        
}
    
24.05.2014 / 03:42