Home > All, PHP, Web > Themes in CakePHP 2.0.0

Themes in CakePHP 2.0.0

I’ve spent the best part of half a day trying to figure out why themes were not working for me in CakePHP 2.0.0

The closest I got to a solution can be found over on stackoverflow.com.

Difference is that you need to set $this->viewClass to ‘Theme’ instead of $this->view, but there are 2 more unmentioned issues with the sample code provided as a solution:

public function beforeRender() {
	if ($this->RequestHandler->isMobile()) {
		$this->viewClass = 'Theme';
		$this->theme = 'mobile';

The first is that RequestHandler has been replaced by request.

So you may use:

if ($this->request->isMobile()) {


if ($this->request->is('mobile')) {

The other is that despite you’ve named your theme ‘mobile’, CakePHP’s new CamelCasing behaviours will turn this into ‘Mobile’. Because of this, you need your theme’s files to be located in ‘app/View/Themed/Mobile‘, and not in ‘app/View/Themed/mobile‘.

Categories: All, PHP, Web