简体   繁体   English

Yii Framework如何从Controller调用View?

[英]Yii Framework how to call View from Controller?

this is my controller file like. 这是我的控制器文件。

class MyController extends CController
{
    /**
     * Index action is the default action in a controller.
     */
    public function actionIndex()
    {
        //call view file like abc.php
    }

}

this is my view/abc.php file 这是我的view / abc.php文件

<html>
    <head>
        <title>Home Page</title>
    </head>
    <body>
        <h1>Home Page</h1>
    </body>
</html>

how to call abc.php file into my controller. 如何将abc.php文件调用到我的控制器中。

Move your abc.php file into the views/My directory and then write. 将您的abc.php文件移动到views / My目录中,然后编写。

public function actionIndex()
{
   $this->render('/abc');
}
public function actionIndex()
{
   $this->render('abc', array(
        'model' => $model, // Model with the values to show on the view file.
    ));
}

Move your abc.php file into the views/MyController directory, and then you can use $this->render('abc.php'); 将您的abc.php文件移动到views / MyController目录中,然后您可以使用$this->render('abc.php'); function. 功能。 As it currently stands, the view can be loaded using $this->render('/abc.php'); 就目前而言,可以使用$this->render('/abc.php');加载视图$this->render('/abc.php'); . I'd also suggest you listen to the comments left by others: do not leave your view in views/, and do not output html and head and body tags and such in your view. 我还建议你听别人留下的评论:不要把你的视图留在视图中,也不要在你的视图中输出html和head和body标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM