How does yii enable the system to call layout files in Protected/views/layouts/by default?

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.