[CakePHP]: How to setup and use layout


Posted on 2015-11-18 10:18:44

When we write an application for Framework . default has supported us Interface available. But sometimes, depending on the preferences, needs and trends ... Should mandatory designers and programmers should have the interface ( layout ) for himself. Posts will guide how we create one layout for yourself and how to apply 1 Helper CakePHP Framework into their applications.
When analyzing one site, generally seen include the following major components:
To apply to be a strong support to make power load layout of CakePHP FrameWork , we analyze the composition of fixed and mobile components :
So we to avoid the disposal of fixed components in the controller need only write one class Hepler to display it. Also active ingredients will be handled through Controllers.
What files need to be prepared in Tutorial Layout CakePHP Framework as follows:
+ app/ : -app_controller.php + app/controllers/templates/ : -templates_controller.php (Controller chính để load layout) + app/views/templates/ : – index.ctp – view.ctp + App / views / helpers /: - common.php (Create fixed components: menu, header, footer) + - Template.ctp (File content layout)
+ app/webroot/css/ : – style.css (file CSS của layout)
Create file app_controller.php (app/)
Create file common.php (app/views/helpers/)
Create file templates_controller.php (app/controllers/templates/) : Create layout files template.ctp (app / views / layouts / template.ctp): This file contains the content layout consists of fixed components and components as originally described. The content of this file consists of HTML and PHP ... Create file style.css (app/webroot/css/style.css) Figure describing the file template.ctp use helper files common.php ( click on image to enlarge ) cake_layout_03 As usual, you create one fuction for 1 Controller, then we must create the corresponding view file to display the contents of the file view this example we do.Trong Controller Templates with 2 function is index () and view () , should have 2 files view is: index.ctp and view.ctp to display the corresponding content.
But we're using layout template.ctp (app / views / layouts / template.ctp), so just create 2 files view.ctp index.ctp and contents of two files you vacate. Example function index () is called, it will load the file index.ctp and automatically loaded into the layout file (app / views / layouts / templates.ctp).
Figure describes the file view file loaded template.ctp ( Click on image to view larger image )
Test applications: