Reputation: 47
I am a newbie at yii . I have a page called main.php . I want some of the other pages to use main.php as layout. my project views are in "site" folder. I create a folder for that views and a separated controller. but it doesn't work.I add $this->layout = 'main' to my project
Upvotes: 0
Views: 335
Reputation: 4607
For changing for ALL controllers and actions you must add this in your config/main.php
file:
[
// ...
'layout' => 'main',
'components' => [
//...
]
]
Change in one controller:
class SiteController extends Controller
{
public $layout='//layouts/main';
public function init() {
// ...
}
//...
}
Change just in one action:
public function actionIndex()
{
$this->layout = 'mian';
return $this->render('index', ['model' =>$model]);
}
Upvotes: 0
Reputation: 11
Put your main.php
or any layout files in views/layouts
folder.
Use this in controllers: public $layout = '/main';
Or in actions: $this->layout = '/main';
Upvotes: 1
Reputation: 133380
In your Yii2 scaffolding should be there a directory
your_application/views/layouts
put the layout file main.php in this dir
(or edit or replace the existing one)
once you have done in the controllerAction where you need the new layout assign the layout
$this->layout = 'main';
.
class YourController extends Controller
{
....
public function actionYourAction()
{
.......
$this->layout = 'main';
return $this->render( .... ]);
}
Upvotes: 0