PHP Symfony Route有一些缺少必需参数

时间:2011-11-04 14:05:00

标签: php model-view-controller symfony1 symfony-1.4

我在使用带有url_for方法的对象时遇到了问题,我认为这个想法是自动找到任何需要的parapeters吗?

The "/publish/:id/:token" route has some missing mandatory parameters (:id, :token).

的routing.yml

post_publish:
  url:     /publish/:id/:token
  options:
    model: HookupPost
    type:  object
    method_for_criteria: doSelectOneInactive
  param:   { module: post, action: show }
  requirements:
    id: \d+
    token: \w+
    sf_method: [GET]

newSuccess.php

<?php echo public_path(url_for("@post_publish", $post), true); ?>

操作传递$ post并包含最近创建的帖子!

有谁知道为什么会出现这种错误?我误解了什么吗?

谢谢,

2 个答案:

答案 0 :(得分:2)

你错过了sfDoctrineRoute声明:

post_publish:
  url:     /publish/:id/:token
  class:   sfDoctrineRoute
  options:
    model: HookupPost
    type:  object
    method_for_criteria: doSelectOneInactive
  param:   { module: post, action: show }
  requirements:
    id: \d+
    token: \w+
    sf_method: [GET]

然后你可以这样做:

<?php echo public_path(url_for("post_publish", $post), true); ?>

参考:http://www.symfony-project.org/jobeet/1_4/Doctrine/en/05

答案 1 :(得分:0)

尝试:

<?php echo public_path(url_for("post_publish", 
        array( 'id' => $post->id, 'token' => $post->token )), true); ?>

或类似的内容,具体取决于您的Post课程。