PHP chat group: 256726721
When we use yii for development, we usually separate the front and back ends.
At this time, I did not think of using the yii module function. At this time, most people will encounter a problem. The front-end and backend should use different layout files. What should I do? In fact, yii provides this function. Let's take a look at how to do it.
We have created an admin module to create a AdminController. php controller.
650) this. width = 650; "src =" ../attachment/201202/150919486 .png" border = "0"/>
For example, I want to call this modules/admin/views/layouts/column2.php View File.
Write this in the controller file contrllers/AdminController. php.
Public $ layout = '/layouts/column2 ';
Note that the preceding is/not //
If it is //, protected/views/layouts will be called by default.
Here is the absolute and relative relationship.
Or public $ layout = 'column2 '; // column2 can be changed to the file you want to use
Okay, here the problem is basically solved. I am talking about it. A lot of people here think that the work has been completed. I found that the View File has not been changed ??? What's going on? This is also a problem that many people may encounter.
We use gii curd to create and generate the controller. The column2.php View File is used by default.
Open the columm2.php file and find
<? Php $ this-> beginContent ('// layouts/main');?>
It turned out to be a ghost here. Haha, we just need to change it.
<? Php $ this-> beginContent ('/layouts/main');?>
Or
<? Php $ this-> beginContent ('application. modules. admin. views. layouts. main');?>
<Div class = "container">
<Div class = "span-19">
<Div id = "content">
<? Php echo $ content;?>
</Div> <! -- Content -->
</Div>
<Div class = "span-5 last">
<Div id = "sidebar">
<? Php
$ This-> beginWidget ('zii. widgets. cportlet', array (
'Title' => 'operations ',
));
$ This-> widget ('zii. widgets. CMenu ', array (
'Items '=> $ this-> menu,
'Htmlopexception' => array ('class' => 'operations '),
));
$ This-> endWidget ();
?>
</Div> <! -- Sidebar -->
</Div>
</Div>
<? Php $ this-> endContent ();?>
End
PHP chat group: 256726721
This article from the "Candlelight to heaven-IT technology road" blog, please be sure to keep this source http://wuhai.blog.51cto.com/2023916/782738