SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)

    Zend: Get controller in layout.phtml

    I'm trying to set up a function so that I can get the pages current controller from within a layout. Because $this->getRequest()->getControllerName() cannot be used in layout I was looking for a way to use it somewhere else and then set it in the registry. However I've never used the registry and beyond setting and then calling both in the layout, I cannot seem to get it to work.

    Perhaps there is a command I'd be able to use straight from the layout to do this? If not then I'd need help setting a registry value as a bootstrap.

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sounds like a bad idea.

    why not inject data you want from controller into layout/view ?

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by ctx2002 View Post
    sounds like a bad idea.

    why not inject data you want from controller into layout/view ?
    Then I'd have to remember to initialize it in every controller I create or else it fails. Whats wrong with bootstrapping this? I know that this sort of stuff is common practice, however I have not messed with bootstrapping or the registry so I am having trouble with it.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "$this->getRequest()->getControllerName()" , so you want a name of controller. just inject that into your view/layout from action method.

    "Then I'd have to remember to initialize it in every controller", your controller should have a common parent. so you can inject that name from parent contructor method.

    this is a common practise for zendframe programming. we have a common parent class for all controllers.

    for example:

    make a parent class:

    myAppController extends Zend_Controller_Action
    {}

    then when need an error controller, we do like this:

    ErrorController extends myAppController
    {}

    "Whats wrong with bootstrapping this", in bootstraping code, how do you know which page is going to be viewed by a vistor / how do you know which controller is used?

    for example: In errorController, your need a name of error controller, in newsController, you your need a name of news controller.


Bookmarks

Posting Permissions

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