CakePHP notes--view Layer _php Tutorial

Source: Internet
Author: User
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 layouts A layout contains all the performance codes that are wrapped outside of 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 in the default layout when the page is render. Whenever you need to, you can create as many layout as you want for your cake site, just put them in the App/views/layouts directory and use the controller's $ in your controller action Layout variable or setlayout () method to switch layout. The Elements element element is produced primarily for code or code block reuse. Many applications have some layer of code that repeats on each page, and sometimes they are just different places in layout. Cake can help you replicate certain chunks of the 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 seen as a mini-view that can be included in other view. All element lives under the/app/views/elements directory and has a. ctp file name extension. By default, element does not have access to any data. To have access to the data, you need to pass the data to it in an array, and don't forget to name the data (key-value pairs). To invoke an element without parameters Renderelement (' Helpbox ');?> calls an element and passes in an array containing the data 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 (something similar to using a controller set () in a view). In this example above, the/APP/VIEWS/ELEMENTS/HELPBOX.CTP file can use the $helptext variable. Of course, if you pass an array to element it will contain more information. Element makes the view more readable, and the part of the element that duplicates the render is placed in the corresponding element file. Of course they can also help you reuse content chunks in your site.

http://www.bkjia.com/PHPjc/477127.html www.bkjia.com true http://www.bkjia.com/PHPjc/477127.html techarticle 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 ...

  • 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.