symfony按钮_传递参数
我在 Symfony 1.4 中有一个 button_to 组件,它调用一个接收参数(slug)的路由。但我无法让 Symfony 识别我发送的参数。我用 link_to 尝试过同样的事情,效果很好。
这是我的代码:
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']);
}
我得到的只是以下 500 错误:
“/entry/:slug”路线有一些 缺少强制参数 (:slug)。
我也尝试过更改模板代码:
<?php echo button_to('ButtonName', 'entry_show?' . 'slug='.'this-is-my-slug') ?>
但无济于事......
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
您需要 @ 符号来绑定到路由配置中的命名路由,并且参数
slug
是 URI 参数的一部分,而不是button_to
的第三个参数> 功能。Try this:
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 thebutton_to
function.您是否尝试为 slug 参数设置默认值?
例如
Did you try to set a default value for your slug parameter ?
Such as