我在使用url_for方法的对象时遇到了问题,我认为这个想法是自动找到任何需要的参数?
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由动作传递并包含最近创建的post!
有谁知道为什么会出现这个错误?我误解了什么吗?
谢谢,
您错过了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
尝试:
<?php echo public_path(url_for("post_publish",
array( 'id' => $post->id, 'token' => $post->token )), true); ?>
或者类似的东西,取决于你的Post
类。