#70 ✓resolved
Joshua Paine

getting a urlTo another controller's method should be much more concise, like so...

Reported by Joshua Paine | February 13th, 2009 @ 11:00 PM | in 0.11.1

Already can call $this->urlTo('methodName'), but to get the path for a method of another class requires instantiating it and using urlTo on the new instance. It's verbose, it takes at least to lines, and it obscures what you're actually trying to do. This would be so much nicer:

$this->urlTo('FooController::bar');

And it can be implemented something like this (Added at the beginning of urlTo):

if(strpos('::',$methodName)!==false) { list($controllerName,$methodName) = explode('::',$methodName,2); $controller = new $controllerName($this->application); return $controller->urlTo($methodName); }

You still have to Library::import the relevant class beforehand, but I'm ok with that, personally.

Comments and changes to this ticket

  • Joshua Paine

    Joshua Paine February 14th, 2009 @ 05:31 PM

    ick--just noticed what lighthouse did to my code. But more importantly, the args of strpos are reversed. Let's try this again:

    if(strpos($methodName,'::')!==false) {
        list($controllerName,$methodName) = explode('::',$methodName,2);
        $controller = new $controllerName($this->application);
        return $controller->urlTo($methodName);
    }
    
    
  • Kris Jordan

    Kris Jordan February 16th, 2009 @ 02:48 PM

    • Milestone set to 0.11.1
    • State changed from “new” to “resolved”

    Thanks for the submission - great improvement in the API!

    This has been added to the source tree with commit 2c3b1a0.

  • joazito

    joazito May 16th, 2009 @ 11:35 AM

    In order for this to work with arguments I needed to replace this line:

    return $controller->urlTo($methodName);

    With this below:

    return call_user_func_array(array($controller, 'urlTo'), array_merge(array($methodName), $args));

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Recess PHP Framework is an open source, full stack, RESTful PHP framework.

http://www.recessframework.org/

People watching this ticket

Pages