Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-30-2007, 02:45 PM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default forwarding how to use ?

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-31-2007, 04:02 AM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Cool Found 'A' way

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-31-2007, 06:38 AM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default

Hi,

Is not quite same thing but we discussed about this here too:

Zend_View, without header/footer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-01-2007, 02:57 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 116
Default

the _forward function forwards after the current action has run, just in case you did know
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-02-2007, 12:56 AM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-03-2007, 09:28 PM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 116
Default

Quote:
Originally Posted by asabi View Post
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 ?
This is my view, sub requests would not really fit well in as a controller action because an action should be treated as a whole page and not as a header or as a footer. As for 'sub requests' for headers/footers, including a header and footer in the view is just as effective and cleaner because all view content is contained within the view. Or you could just create a class to generate the header and view?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-09-2007, 04:47 PM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default

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 ...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-04-2008, 12:34 PM
Junior Member
 
Join Date: May 2008
Posts: 5
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-04-2008, 01:13 PM
Junior Member
 
Join Date: Oct 2007
Posts: 24
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 06-06-2008, 09:54 AM
Junior Member
 
Join Date: May 2008
Posts: 5
Default

Hi, what you are doing sounds like it could be about what i want to do.

got any tutorial or documentation i can read to get started there?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:15 AM.