0

I would like to know if someone could explain me what happens exactly when we call a "render".

Let me introduce you my problem:

This is my action:

public function actionIndex()
{
    $new_user = new CustomUser;
    $new_person = new CustomPerson;

    $tab_person = $this->getListPerson();
    $this->render('index',array('tab'=>$tab_person,
                                'user'=>$new_user,
                                'person'=>$new_person));
}

And this is my index view:

.
. 
.
</p> <br/>   
<?php $this->renderPartial('person-form', array('person'=>$person,
                                                'user' =>$user ));
?>

So my problem is that the loading page time is very long. If I put a

die("die");

just befor the render in my actionIndex or at the end of my view (after the renderPartial) the execution is very fast. I'll see "die"(and my index page if I put the statement at the end of it) after 0.3 second. But if I put it after my render or I don't put it, then my page is going to be loaded correctly but in 4-5 secondes.

So I think I didn't understand very well what happens after a render. I repeat if I stop the execution at the end of my view page it's very fast, but at the end of my action it's very slow. I thought about js and css, but after looking into I didn't see anything and Firebug shows me that these files are loaded very quickly. And if I put the "die()" statment at the end of my layout main.php it's very fast as well.

enter image description here

So I know that render will show the page and wrap it in the layout but is there another thing which maybe could make the action very slow?

If anybody has an idea about my problem I would be very grateful.

Sorry if I did mistakes, English is not my mothertongue.

Thank you for reading me, have a good day :)

Michaël

4

2 回答 2

0

这可能看起来令人困惑的一个原因是它可能不是缓慢的“渲染”。可能是加载模型和关系很慢,但默认情况下它们是延迟加载的。这意味着在请求它们的代码被命中之前不会查询数据库,这通常在视图中。

这可以解释为什么渲染速度很慢。所以就像其他人说的那样,您需要在页面或日志中启用日志记录到萤火虫。然后,您可以检查任何慢查询或组件。

于 2013-01-07T10:08:16.620 回答
0

据我了解,它不应加载较慢。也许您在页面上加载了其他内容。尝试在屏幕上启用日志:http ://www.yiiframework.com/wiki/58/sql-logging-and-profiling-in-firebug-yii-1-1/ 。查看视图渲染后是否执行了任何操作。

于 2013-01-07T01:59:11.183 回答