Cake Notes--view Layer

Source: Internet
Author: User
Tags add array key php file php code variable access
A view is a page template, usually named after the action. For example, Postscontroller::add's view is located in/APP/VIEWS/POSTS/ADD.CTP. Cake view is a very simple PHP file, so you can use any PHP code in it.       Layouts layout   A layout (layout) contains all the performance codes that are wrapped outside the view. Layout files are placed in the/app/views/layouts directory. You can override a default layout to replace the cake default layout located in/app/views/layouts/default.ctp. Once a new default layout is created, the contents of the controller view are replaced with the default layout when the page is render. Whenever necessary, you can create any number of layout for your cake site as long as you put them in the App/views/layouts directory and use controller $ in your controller action Layout variable or setlayout () method to toggle layout.       Elements elements     element elements are generated primarily for code or code block reuse. Many applications have a layer of code that repeats on every page, and sometimes they are just different places in the layout. Cake can help you replicate certain blocks in your site if needed. We refer to these reusable page blocks as element (elements). Ads, help boxes, navigation bars, menus, and illustrations are all cake implemented as element. An element can actually be viewed as a mini-view that can be included in other view. All of the element lives in the/app/views/elements directory, and the file name extension is. CTP.   By default, element cannot access any data. To give it access to data, you need to pass the data to it in an array, and don't forget to name the data (key-value pairs).   Call an element   <?php echo $this->renderelement (' Helpbox ') without parameters;?>   Call an element and pass in an array containing the data. nbsp ?PHP echo   $this->renderelement (' Helpbox ', Array ("HelpText" => "Oh, this text is very helpful."));    ?>   In the element file, all incoming variables can be used by their key names in the parameter array (somewhat similar to using the set () variable in the view inside the controller). In the example above, the/APP/VIEWS/ELEMENTS/HELPBOX.CTP file can use the $helptext variable. Of course, if you pass an array to the element, it will contain more information. The element makes the view more readable, while the part of the render repeating element is placed in the corresponding element file. Of course, they can also help you reuse content blocks in your site.  

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.