Renish Khunt
Renish Khunt

Reputation: 5824

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

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

how to call abc.php file into my controller.

Upvotes: 0

Views: 3453

Answers (3)

user2238699
user2238699

Reputation:

Move your abc.php file into the views/My directory and then write.

public function actionIndex()
{
   $this->render('/abc');
}

Upvotes: 2

Parham Doustdar
Parham Doustdar

Reputation: 2039

Move your abc.php file into the views/MyController directory, and then you can use $this->render('abc.php'); function. As it currently stands, the view can be loaded using $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.

Upvotes: 0

Daniel Vaquero
Daniel Vaquero

Reputation: 1305

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

Upvotes: 0

Related Questions