Вопрос

I have a button_to component in Symfony 1.4, which calls a route that receives a parameter (a slug). But I cannot get Symfony to recognize the parameter I'm sending. I have tried this same thing with a link_to and it works fine.

Here's my code:

routing.yml

entry_show:
  url:                /entry/:slug
  class:              sfDoctrineRoute
  options:
    model:            ProjectEntry
    type:             object
    method:           getEntryBySlug
  param:              { module: entry, action: show }

template:

<?php echo button_to('ButtonName', 'entry_show', array('slug' => 'this-is-my-slug')) ?>

Entry model:

public function getEntryBySlug($parameters)
{
  return $this->findOneBySlug($parameters['slug']);
}

All I get is the following 500 error:

The "/entry/:slug" route has some missing mandatory parameters (:slug).

I have also tried changing the template code with:

<?php echo button_to('ButtonName', 'entry_show?' . 'slug='.'this-is-my-slug') ?>

but to no avail...

any ideas?

Это было полезно?

Решение

Try this:

<?php echo button_to('ButtonName', '@entry_show?slug=this-is-my-slug') ?>

You need the @ symbol to bind to a named route in the routing config, and the parameter slug is part of the URI argument, not the 3rd argument of the button_to function.

Другие советы

Did you try to set a default value for your slug parameter ?

Such as

  param:              { module: entry, action: show, slug: default-slug }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top