PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 18, 2022

[FIXED] How to enable a theme for all views?

 February 18, 2022     cakephp, cakephp-3.0, themes     No comments   

Issue

I am working on a CakePHP 3 project and I'm new to CakePHP.

I have baked a theme MyTheme in plugins/MyTheme.

I have also configured default.ctp in plugins/MyTheme/src/Template/Layout/ directory and all css and js files in plugins/MyTheme/webroot/css/ and /plugins/MyTheme/webroot/js/ directories.

How do I enable this theme for all views (master theme) ?


Solution

[...] How do I enable this theme for all views (master theme) ?

By defining the theme to use (either via the $theme property (before CakePHP 3.1), or via the view builders theme() method) in a controller that all your applications controllers extend, which by default should be AppController.

Something along the lines of

//...

class AppController extends Controller
{
    // With CakePHP < 3.1
    public $theme = 'MyTheme';

    // With CakePHP >= 3.1
    public function beforeRender(\Cake\Event\Event $event)
    {
        $this->viewBuilder()->theme('MyTheme');
    }
}

See also

  • Cookbook > Controllers > The App Controller
  • Cookbook > Views > Themes


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing