繁体   English   中英

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

[英]PHP Symfony Route has some missing mandatory parameters

我在使用带有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由操作传递并包含最近创建的帖子!

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

谢谢,

你错过了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类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM