Jon B.
Jon B.

Reputation: 13

CakePHP - Letting the User Select the Layout

Im working on a CakePHP application that will display a DVD collection. I would like to include a Dropdpwn Menu where the user can select their on view/colour scheme. Nothing fancy, it just needs to either change the layout file for the CSS file. Either will work.

Any tips? Can't seem to figure it out.

Regards, Jon

Upvotes: 1

Views: 86

Answers (1)

Corie Slate
Corie Slate

Reputation: 616

Use Themes to switch either layout, css, or both.

In your AppController.php add:

$this->theme = 'Fancy';

This will look for your default layout in App/View/Themed/Fancy/default.ctp. You choose what you want to customize with a theme. If you don't have a special layout file for the Fancy theme, CakePHP will default to App/View/Layouts/default.ctp. Likewise, you can choose to provide a special stylesheet in your theme which would go in App/View/Themed/Fancy/webroot/css/default.css and if not CakePHP would use App/View/webroot/css/default.css.

You can set the user's theme selection to a Cookie so it's remembered.

You didn't say which version of CakePHP you're using, but the solution will be similar in either 2.x or 3. The above links are to the 2.x Cookbook.

Upvotes: 3

Related Questions