symfony按钮_传递参数

发布于 2024-10-25 13:21:25 字数 984 浏览 9 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在你怀里撒娇 2024-11-01 13:21:25

试试这个:

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

您需要 @ 符号来绑定到路由配置中的命名路由,并且参数 slug 是 URI 参数的一部分,而不是 button_to 的第三个参数> 功能。

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.

暗地喜欢 2024-11-01 13:21:25

您是否尝试为 slug 参数设置默认值?

例如

  param:              { module: entry, action: show, slug: default-slug }

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

Such as

  param:              { module: entry, action: show, slug: default-slug }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文