Router::connect static parameters #607

Closed
xmeltrut opened this Issue Aug 9, 2012 · 6 comments

Comments

Projects
None yet
2 participants

xmeltrut commented Aug 9, 2012

According to the manual, you can pass static parameters into routes.

Router::connect('/socks', array('Products::view', 'id' => 72739));

However, this doesn't seem to work in practice.

Router::connect('/blog', array('Articles::index', 'id' => 123));
Router::connect('/test', array('Articles::post', 'slug' => 'hello-world'));

Both of those generate a missing argument 1, or given default values, remain blank.

Owner

nateabele commented Aug 9, 2012

Your syntax definitely looks correct. Can you show me what you're calling to generate the actual links (i.e. calling the Router directly vs. using a helper method, etc.)?

xmeltrut commented Aug 9, 2012

Helper method in the view? I'm not using any at the moment, I just connected the route up in my bootstrap/routes.php file and punched it in manually.

Owner

nateabele commented Aug 9, 2012

Right, so that connects up the routes, but then what do you do to actually attempt to generate a URL from it? Or are you talking about just trying to load a page when you browse to /blog?

Sorry if I'm missing something obvious here.

  • Nate

On Thursday, August 9, 2012 at 10:29 AM, Chris Worfolk wrote:

Helper method in the view? I'm not using any at the moment, I just connected the route up in my bootstrap/routes.php file and punched it in manually.


Reply to this email directly or view it on GitHub (#607 (comment)).

xmeltrut commented Aug 9, 2012

Sorry, yes, I'm just talking about trying to load the page by browsing to /blog. So in theory it should be connected up to my Articles::index method and send id as a parameter, unless I've misunderstood.

class ArticlesController extends Controller {

    public function index ($id) {
        $article = Article::getRepository()->findBy(array('id' => $id));
        return compact('article');
    }

But if I run this, it doesn't pass the argument through, and I get a missing argument 1 error.

Owner

nateabele commented Aug 9, 2012

Ah, yes. I assume you're coming from Cake? Passed parameters don't work the same in Lithium (in fact, I kind of hate the way they work, and am probably dropping them in future versions in favor of something like what li3_resources does, but I digress…)

For your purposes, the simplest thing to do would be to rewrite your method per the following:

public function index() {
    $article = Article::getRepository()->findBy(array('id' => $this->request->id));
    return compact('article');
}
  • Nate

On Thursday, August 9, 2012 at 11:20 AM, Chris Worfolk wrote:

Sorry, yes, I'm just talking about trying to load the page by browsing to /blog. So in theory it should be connected up to my Articles::index method and send id as a parameter, unless I've misunderstood.
class ArticlesController extends Controller { public function index ($id) { $article = Article::getRepository()->findBy(array('id' => $id)); return compact('article'); }
But if I run this, it doesn't pass the argument through, and I get a missing argument 1 error.


Reply to this email directly or view it on GitHub (#607 (comment)).

xmeltrut commented Aug 9, 2012

Ah ok, thanks.

@nateabele nateabele closed this Sep 15, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment