Switch to Bing in English
Copilot
Your everyday AI companion
Explore these results from Bing
    Upvotes3Top Answeranswered Feb 25, 2010 at 17:34

    Short answer: maybe you're doing it wrong.

    Long answer: Scripts should not be controller dependent. It's 'theoretically' wrong, and cake does not like people who doesn't adhere to the mvc pattern.

    Workaround (because sometimes you just need to): You can set in beforeRender a var:

    function beforeRender() {
    parent::beforeRender();
    $this->set('scripts', array('script1', 'script2' ...));
    }

    And in the layout check for $scripts and add them.

    Content Under CC-BY-SA license
    Was this helpful?
  1. cakephp: can I set $scripts_for_layout from within a controller?

    I'd like to set the layout's $scripts_for_layout from within the controller. Is this possible, and if yes how?
    ✓ Short answer: maybe you're doing it wrong. Long answer: Scripts should not be controller dependent. It's 'theoretically' wrong, and cake does not like pe…
    Feedback
  2. How to set the content of the $script_for_layout in cakephp?

  3. Class View | CakePHP 2.0

  4. Set $scripts variable for layout in AppController and ...

  5. People also ask
    $content_for_layout is deprecated and will be removed in CakePHP 3.0. Use the content block instead. Content to render in a view, wrapped by the surrounding layout. if there is an error in the view. Allows a template or element to set a variable that will be available in a layout or other element. Analogous to Controller::set ().
    You need to tell CakePHP to use your custom layout. In you controller ( PostsController) set the layout into the initialize() function. Also you can use the different layout for different function by defining the layout into different functions.
    CakePHP’s default layout is located at /app/View/Layouts/default.ctp . If you want to change the overall look of your application, then this is the right place to start, because controller-rendered view code is placed inside of the default layout when the page is rendered. Other layout files should be placed in /app/View/Layouts .
    book.cakephp.org
    CakePHP’s Element and Layout feature helps you to customize your application layout. This tutorial is designed to help you for CakePHP theme integration by creating elements and layout. Elements are the small and reusable bits of view code. Layouts are the template files that contain presentational code together with rendered Elements.
  6. CakePHP2を美味しく食べたい:$scripts_for_layoutの使い方 ...

  7. Class View | CakePHP 2.4

  8. CakePHPでレイアウトを活用する – helog

By using this site you agree to the use of cookies for analytics, personalized content, and ads.Learn more about third party cookies|Microsoft Privacy Policy