2009年2月25日星期三

Re: [fw-mvc] passing parameters to the action controller

Some applications and some programmers only want request data in their request object ($_GET,$_POST,$_SESSION,$_SERVER,etc),. 

Zend Framework allows for another avenue for passing parameters throughout your application, using invokeArgs, This allows you to bypass the Registry and keep the Request clean.

On Feb 25, 2009, at 5:01 PM, Seth Atkins wrote:

Yes, that's it. My parameters are accessible with that method. The documentation isn't all that clear on this topic. If you store it as a setParam method, you would think retrieving it would be through a getParam method, especially since one exists in the action controller class. That's what I get for thinking!
 
Yes, I could use the registry as well, but my question is more of a learning question. I'm new to this framework and trying to understand how things fit together, how to pass things between components of the framework, what talks to what, and so forth. Example code (like the Akrabat tutorial) typically only shows you one way of doing something, and I'm trying to learn more than what one person prefers to do and take my learning a step deeper. Which is why I'm reading through the docs as I go, and experimenting as I put together my first project using this framework. I've spent a good bit of time digging through code to answer a previous question, and thought it might be quicker to just ask this one instead of digging yet again. Turns out I was correct. This did turn out faster than going through a bunch of code.
 
 
--Seth
 


From: Shawn Ostler [mailto:sosy@mac.com]
Sent: Wednesday, February 25, 2009 4:56 PM
To: Atkins, Seth (RICH1:5278)
Cc: fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] passing parameters to the action controller

Do you get the param by calling $this->getInvokeArgs() in the controller?

You could use Zend_Registry::set() and Zend_Registry::get() to pass your params.

On Feb 25, 2009, at 3:26 PM, Seth Atkins wrote:

I'm trying to find the proper way of passing objects or parameters from the front controller to the action controller. I've read the documentation, so please skip the RTFM stuff... :-). In the docs it says this:
 
10.3.4
 In the introduction, we indicated that the front controller also acts as a registry for the various controller components. It does so through a family of "param" methods. These methods allow you to register arbitrary data -- objects and variables -- with the front controller to be retrieved at any time in the dispatch chain. These values are passed on to the router, dispatcher, and action controllers. The methods include:
 
So as I read this, if in the bootstrap script I do this:
 
$front->setParam('foo', 'bar');
 
then parameter 'foo' should have value 'bar' within the action controller. However, in the action method of my action controller, lets say, MyactionController this statement only shows three parameters, not the one I just set.
 
$this->_getAllParams();
 
What I get returned from that is three parameters for action, controller, and module. foo => bar isn't there. Maybe I'm misreading the documentation, but it says "arbitrary data", and that those values are passed to the action controller. Am I barking up the wrong tree, or did I miss something?
 

Seth


Shawn Ostler
InclusiveDv




Shawn Ostler
InclusiveDv



没有评论: