Using the Yii layout, add <?php echo $content;?> this sentence, it automatically adds a DIV package to the sub-page

Source: Internet
Author: User
Tags yii

Using the Yii layout, add <?php echo $content;?> this sentence, it will automatically add a div package on the sub-page, and the div ID named Id=content, this and the existing ID is duplicated, how to solve?

Http://hi.baidu.com/jyhscy/item/2b05034c9d9f1e35fb8960d1

Relationship between the column of layout and the main file in Yii

After Yii creates the application results, in the view/layouts/directory, 3 layout pages are generated:

-->main.php

-->column1.php

-->column2.php

Since the first use of an application created by the command-line shell approach, Yii itself creates a controller component: Controller.php, which inherits the Ccontroller controller, which is located in the/components directory:

+++++++++++++++++++++++++++++++++++++++++++

<?php

Class Controller extends Ccontroller

{

Public $layout = '//layouts/column1 ';

Public $menu =array ();

Public $breadcrumbs =array ();

}

?>

+++++++++++++++++++++++++++++++++++++++++++

The default page for layout in the file is: '//layouts/column1′, and then view/layouts/, Column1 calls the main.php view file again:

+++++++++++++++++++++++++++++++++++++++++++

<?php $this->begincontent ('//layouts/main ');?>

<div id= "Content" >

<?php echo $content;?>

</div><!--Content--

<?php $this->endcontent ();?>

+++++++++++++++++++++++++++++++++++++++++++

After the main.php file is loaded, the content in the containing index.php is the content in $content.

If the controller is automatically generated by this scaffold of the GII, then all the controllers will inherit from the controller and unofficially said inherited and Ccontroller controller, in the page view rendering, a layer of column1.php intermediate view.

So when Yii $this a page of->render (' index '), it uses column1.php to contain main.php, and then main.php contains index.php and finally returns content. (This is for inheriting controller mode).

And as for column2.php only what, seems to be a soy sauce, no use.

If we want to change the default layout view file, either directly in components/controller.php change $layout = '//layouts/newlayout_name ', or when the controller inherits, directly extends Ccontroller instead of controller, then configure config/main.php:

++++++++++++++++++++++++++++++++++++++++++++

Return Array (

..................

' BasePath ' =>dirname (__file__). Directory_separator. '.. ',

' Name ' = ' Web application ',

' Layout ' = ' newlayout_name '

..................

+++++++++++++++++++++++++++++++++++++++++++++

Then call it in the controller:

+++++++++++++++++++++++++++++++++++++++++++++

TestController to customize a test controller, inherit Ccontroller directly, inherit controller by default

Class TestController extends ccontroller{

..................

}

++++++++++++++++++++++++++++++++++++++++++++++

Of course, you can also set the Layout property directly in the controller, overriding the default layout, making the view rendering more flexible. Here is just a description of the relationship between layouts/, main.php and column1.php, and index.php in/view.

++++++++++++++++++++++++++++++++++++++++++++++

Override the setup layout directly in the controller:

Public $layout = '//layouts/newlayout_name ';

++++++++++++++++++++++++++++++++++++++++++++++

So just open the column1.php and change the div inside to OK

Using the Yii layout, add <?php echo $content;?> this sentence, it automatically adds a DIV package to the sub-page

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.