|
|||
|
Hi All,
I am new to the framework, so please, go easy on me ;-) I am trying to do the following: I have a module called "admin", inside admin, I have 4 controllers: "wrapper" with "showHeader" and "showFooter" actions "category" with "add" action "disk" with "add" action "index" with "index" action What I'd like to do: from the index/index action: $this->_forward('showHeader','wrapper'); echo($viewHome->render('home.php')); $this->_forward('showFooter','wrapper'); from the ctegory/add action: $this->_forward('showHeader','wrapper'); echo($viewCategoryAdd->render('addCategory.php')); $this->_forward('showFooter','wrapper'); from the disk/add action: $this->_forward('showHeader','wrapper'); echo($viewDiskAdd->render('addDisk.php')); $this->_forward('showFooter','wrapper'); The idea is to request for the header, the main content, and the footer, by just forwarding the request, and later continue with the rest of the action. What I get in the default controller is: the content of home.php, and the footer, but nothing from the header. If I remove the footer call, I get the content, and header (in that order - I thought that I should get the header first, and the content later). Am I making any sense here ? or am I missing the whole thing ? Shouldn't the forward forward the request, and later continue from the caller ? Is there a better, different way to get this working ? HELP :-) Last edited by asabi : 03-30-2007 at 03:11 PM. |
|
|||
|
I did some more research, and eventually went with creating helpers for the view:
inside admin/index echo($viewHome->header()); echo($viewHome->render('home.php')); echo($viewHome->footer()); inside admin/category/add echo($viewCategoryAdd->header()); echo($viewCategoryAdd->render('addCategory.php')); echo($viewCategoryAdd->footer()); So header, and footer are now set as helpers for any of the admin module views. Each of the helpers is creating an instance of a view, with a render call. Please let me know if anyone can think of a better / more appropriate solution, or if you feel it is not right to use the helpers in such a way. Thank you Alon |
|
||||
|
__________________
Zend Framework Tutorials | Zend Framework Forums | Zend Framework IRC Channel | | Zend Framework Resources | CoreShifter |
|
||||
|
the _forward function forwards after the current action has run, just in case you did know
![]()
__________________
Zym Framework - A Zend Framework extension library w/ demo app SpotSec Blog: http://spotsec.com/blog |
|
|||
|
Well, I now understand the way forward works, it just changes the request parameters to point to the next controller.
What I really look for, is a way to do a 'sub' request, something along the lines of creating a new request, to another controller, dispatch it, and use the result inside the current controller. I see a need for it for anything that needs to be repeated in multiple pages, like navigation for example. So, instead of creating another view inside the controller, and render it, why not just call another controller action, which already creates the view, has all of the model calls and the call to render ... I guess everything is a singleton when it comes to the front controller and the request object. Again, do I have anything wrong in my thinking ? Last edited by asabi : 04-02-2007 at 12:59 AM. |
|
||||
|
Quote:
__________________
Zym Framework - A Zend Framework extension library w/ demo app SpotSec Blog: http://spotsec.com/blog |
|
|||
|
I look at 'forward' as a limited version for a sub request, the way I see it is that a sub request is like using another controller / action as a helper.
A sub request at the end of an action would work exactly as forward ... |
|
|||
|
I was looking for a way to do much the same as asabi but couldnt find a way to do it.
So now for this project i have simple classes with __toString methods that generate dynamic little 'building blocks' into the layout. At least it uses the same models as the other parts of the project so theres not too much code duplication. It works but i would have prefered a way to call a controller and action to produce a '5 last comments'-block, or '10 most viewed blogs'-block and so on. If theres a good way to do that i would like to know for the next project. ![]() I know theres an actionStack helper that i havent really looked at enough to know if it would work. |
|
|||
|
Hi,
I am sure I am missing the point here, but the way I am currently doing this is to use a module layout and couple that with Zend_Layout. This way I get the common items, such as header, footer, etc everywhere I want them. I apologize if I misunderstood what you are trying to achieve. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|