A view is a page template, usually named after an action. For example, the view of PostsController::add is located at /app/views/posts/add.ctp. Cake views are very simple PHP files, so you can use any PHP code in them.
Layouts Layouts
A layout contains all the presentation code wrapped outside the view. Layout files are placed in the /app/views/layouts directory. You can override a default layout to replace Cake's default layout located in /app/views/layouts/default.ctp. Once a new default layout is created, the controller view's content will be replaced with the default layout when the page is rendered. You can create as many layouts as you need for your Cake site. Just put them in the app/views/layouts directory and use the controller's $layout variable or the setLayout() method to switch layouts in your controller action. .
Elements
The
element element is mainly generated for the reuse of code or code blocks. Many applications have presentation code that is repeated from page to page, and sometimes it's just in different places in the layout. Cake can help you copy certain sections of your site if needed. We call these reusable page blocks Elements. Advertisements, help boxes, navigation bars, menus and illustrations are all implemented as elements in Cake. An element can actually be regarded as a mini-view that can be included in other views. All elements live in the /app/views/elements directory and have a file extension of .ctp.
By default, element cannot access any data. To give it access to data, you need to pass it the data in an array, and don't forget to give the data a name (an array of key-value pairs).
Call an element without parameters
renderElement('helpbox'); ?>
Call an element and pass in the array containing data
$this->renderElement('helpbox', array(
"helptext" => "Oh, this text is very helpful.")
);
?>
In the element file, all incoming variables can be used through their key names in the parameter array (somewhat similar to variables set with set() using the controller in the view). In the above example, the $helptext variable can be used in the /app/views/elements/helpbox.ctp file. Of course, if you pass an array to element it will contain more information. element makes the view more readable, and the repeated element parts of the render are placed in the corresponding element file. Of course they can also help you reuse content blocks within your site.
http://www.bkjia.com/PHPjc/477127.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477127.htmlTechArticleA view is a page template, usually named after the action. For example, the view of PostsController::add is located at /app/views/posts/add.ctp. Cake views are very simple PHP files, so you...