Reputation: 170
I use the CakePHP framework and I want to have multiple templates in my project.
Is there any way for implementation of multiple templates in CakePHP?
For example, an admin can choose first the or second template in the backend and users can use the same template. (Like in the Joomla backend). If there is any way, how can I implement this?
Upvotes: 2
Views: 1911
Reputation: 27382
Just giving you basic idea about how you can do that.
In app_controller try below code.
<?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 other controller file which extends app_controller add you must have code as below.
<?php
class OtherController extends Controller
{
var public $uses = array('ModelName');
function beforeFilter()
{
parent::beforeFilter();
}
?>
You can also overwrite $this->layout
to every controller action.
Upvotes: 5
Reputation: 1289
You can create different templates in View/layouts
template_1.ctp
, template_2.ctp
with different styles
And create the default.ctp
layout which 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 themes as per documentation
Upvotes: 1