2008年9月12日星期五

Re: [fw-mvc] Strange behavior on Zend_View_Helper_Url

As I could understand, if I pass default, unless I have a variable to be set, it doesn't matter if the reset parameter is true or false.
I use the reset parameter when I have a route with variables, then I don't need to pass its values.
It doesn't not rewrite the controller, module or action settings, for example.

Buuut, the problem was on the route name! I wasn't passing the 'default' in the second parameter.

Now it's working.

Thanks!

On Fri, Sep 12, 2008 at 6:37 PM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- Ramses Paiva <ramses@sourcebits.com> wrote
(on Friday, 12 September 2008, 10:39 AM +0530):
> I noticed that when I print my urls using the Zend_View_Helper_Url (ZF 1.6.0)
> I'm getting it right, but... when I'm accessing through a route, it's printing
> the route.
>
> For example:
> I have a route called 'home' that redirects the request /home to my
> IndexController.
> On my home, I have a link to profile and I'm printing like this:
>
> $this->url(array('controller' => 'profile'));
>
> When I access /index it's working fine printing /profile, but when I access /
> home it's printing the route.

You need to pass a true value to the third parameter of the url() view
helper, which tells it to use only the data you've provided when
creating the URL:

   $this->url(array('controller' => 'profile'), 'default', true);


> If I pass a route name as parameter (i.e., $this->url(array(), 'route';)) it
> works fine in both cases.
>
> It seems that the helper simply rewrites the controller, module and action
> settings sent as parameter with the route settings.
>
> It think it should be slightly different and should work like this:
>
> Route: /home => IndexController;
>
> Accessing the route: /home:
> Link 1: $this->url(array('controller' => 'incompatibleController'), 'home'); //
> Wrong: should throw an exception or, in this case specifically, rewrite the
> settings according to the route settings
> Link 2: $this->url(array('controller' => 'profile')); // Currently, it's
> printing '/home'. In this case, it should ignore the route and print '/
> profile'.
>
> Suggestions?
>
>
> Thanks,
>
> /**
>  * Ramses Paiva
>  * Software Consultant
>  *
>  * SourceBits Technologies
>  * 63, 19th Main
>  * Rajajinagar 2nd Block
>  * Bangalore, KA, India
>  *
>  * Ph  +91 80 4127 7434
>  * Mob +91 97 4237 6432
>  * Fax +91 80 2342 5494
>  * www.sourcebits.com
>   */
>

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


没有评论: