Results 1 to 5 of 5

Thread: How to customize the layout based on the controller?

  1. #1
    mesh2005 is offline Member
    Join Date
    Sep 2009
    Posts
    53

    Default How to customize the layout based on the controller?

    I need to out some javascript code on a page that is processed by controller "A". The problem is controller A shares the same layout as other controllers and I don't wanna put the javascript on all pages. Any ideas?

  2. #2
    odeezy is offline Junior Member
    Join Date
    Oct 2009
    Posts
    3

    Default Use your headScript placeholder

    to include on a per controller basis, you could use the headScript placeholder that the framework provides in your controllers init() method. There are certainly more complex ways but that seems sufficient if the only stipulation is per controller.

    // in Action Controller
    public function init(){
    // to include a file
    $this->view->headScript()->appendFile($filename);
    // or to include arbitrary code
    $this->view->headScript()->appendScript($scriptStr);

    }

    The section in the online docs is:
    61.4.1.9. HeadScript Helper

    cheers.

  3. #3
    mesh2005 is offline Member
    Join Date
    Sep 2009
    Posts
    53

    Default

    this is not working I added the two lines to the init of my controller but I couldn't find the JS scripts when the layout was rendered. Any ideas?

  4. #4
    mesh2005 is offline Member
    Join Date
    Sep 2009
    Posts
    53

    Default

    Now it is working! I needed to add the following to the layout:
    <?php echo $this->headScript() ?>

    Thanks for your help!

  5. #5
    Laura Dean is offline Member
    Join Date
    Jun 2009
    Posts
    80

    Default

    How did you set up your application so that your controllers share a common layout? I have mine set up so that every controller gets its views from views/scripts/<controller_name>/<view_name>.phtml

    But really they are mostly all the same, and I'd like them to access common files, if I can do that without breaking ACL...

Similar Threads

  1. How to change the layout of the error controller?
    By ponchorage in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 06-18-2010, 04:56 PM
  2. Switching Layout based on Module
    By topcatxx in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 10-21-2009, 05:13 AM
  3. how to customize my zf1.8 error
    By rakesh in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 09-29-2009, 11:42 PM
  4. How to alter layout based on current controller
    By MaxG in forum Model-View-Controller (MVC)
    Replies: 0
    Last Post: 09-20-2009, 11:53 PM
  5. Using a Different Layout in a Specific Controller
    By simon2807 in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 02-09-2009, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •