How can I implement multiple patterns in cakephp

I am using the CakePHP framework and I want to have several templates in my project.
Is there a way to implement multiple patterns in CakePHP?

For example, an administrator can select the first or second template in the backend, and users can use the same template. (As in the Joomla backend). If there is any way how can I implement this?

+2
source share
3 answers

Just give you an idea of ​​how you can do this.

In app_controller, try running the code below.

<?php class AppController extends Controller { var $components = array( 'Auth','Session', 'RequestHandler','Email','Gzip.Gzip','SwiftMailer'); var $helpers = array( 'Javascript', 'Form', 'Html', 'Session','Time','Custom','Paginator','Text' ); function beforeFilter() { if(isset($this->params['admin']) && $this->params['admin'] == 1) { $this->layout = "admin"; } else { $this->layout = "default"; } } ?> 

And inside another controller file that extends the app_controller application, you must have the code as shown below.

 <?php class OtherController extends Controller { var public $uses = array('ModelName'); function beforeFilter() { parent::beforeFilter(); } ?> 

You can also overwrite $this->layout for each controller action.

+5
source

you can use this link http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Views.html

I do not use this, but hope this link helps you.

+1
source

You can create different templates in View/layouts

template_1.ctp , template_2.ctp with different styles

And create a default.ctp layout that will include one of the existing templates or set $this->layout = 'template_1'; in the AppController ;

 <?php //default.ctp $loadTemplate = 'template_1.ctp';//value from database or config file? include_once($loadTemplate); ?> 

Or you could use documentation topics

+1
source

All Articles