2009年2月25日星期三

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

-- Seth Atkins <satkins@nortel.com> wrote
(on Wednesday, 25 February 2009, 04:26 PM -0600):
> 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();

The arguments that you push in from the front controller are referenced
independent of the request object as "invocation arguments", or
"invokeArgs". You need to use $this->getInvokeArgs() to retrieve them
(or $this->getInvokeArg($key) to retrieve a single one).

_getAllParams() retrieves parameters from the request object.

> 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?

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: