Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony1 symfony:调用url_for()时出错<;脚本>;标签_Symfony1_Symfony 1.4 - Fatal编程技术网

Symfony1 symfony:调用url_for()时出错<;脚本>;标签

Symfony1 symfony:调用url_for()时出错<;脚本>;标签,symfony1,symfony-1.4,Symfony1,Symfony 1.4,我在这些javascript标记中调用url_for(): <script type="text/javascript"> $.post('<?php echo url_for('category_set_representative_image', array('sf_subject' => $category)) ?>', function(){ alert("fadsf"); }

我在这些javascript标记中调用url_for():

<script type="text/javascript">
    $.post('<?php echo url_for('category_set_representative_image',
array('sf_subject' => $category)) ?>',
           function(){

             alert("fadsf");
           }
    );

</script>
我还有一个路由规则:

category_set_representative_image:
  url:     /rappresentativa
  param:   { module: category_new, action: setRepresentativeImage }
  class:   sfDoctrineRoute
  options: { model: Category, type: object }
注意:如果我调用同一url_for()时远离 标签

有什么想法吗

sf 1.4


Javi

您上面描述的错误与
脚本
标记无关。不管你在哪里使用它(url\u)

首先,我认为,您需要使用
url\u(数组('sf\u route'=>'类别设置代表图像','sf\u主题'=>$category))
url\u('category\u设置代表图像',$category)
。当您需要传递更多参数而不仅仅是对象时,第一个参数很有用

其次(不太重要),可能您需要向URL添加更多参数:

category_set_representative_image:
  url:     /rappresentativa/:id
  param:   { module: category_new, action: setRepresentativeImage }
  class:   sfDoctrineRoute
  options: { model: Category, type: object }
  requirements:
    id: \d+
第三个,检查模块和操作是否确实存在:

// apps/<application>/category_new/actions.class.php
public function executeSetRepresentativeImage(sfWebrRequest $request) {
  $category = $this->getRoute()->getObject();
//apps//category\u new/actions.class.php
公共函数ExecuteStrepresentationImage(sfWebrRequest$请求){
$category=$this->getRoute()->getObject();

希望这会有用。

我认为问题只是与javascript和PHP之间的引号使用不当有关。 试着这样做:

<script type="text/javascript">
$.post('<?php echo url_for("category_set_representative_image",
array("sf_subject" => $category)) ?>',
       function(){

         alert("fadsf");
       }
);

$.post(“”,
函数(){
警报(“fadsf”);
}
);

确实有效:

category_set_representative_image:
  url:     /rappresentativa
  param:  { module: category_new, action: setRepresentativeImage}
  class:   sfDoctrineRoute
  options: { model: Category, type: object }
  requirements: { sf_method: post }
编辑:无论如何,安东卡利亚耶夫说的话也是必要的:

category_set_representative_image:
  url:     /rappresentativa/:id
  param:  { module: category_new, action: setRepresentativeImage}
  class:   sfDoctrineRoute
  options: { model: Category, type: object }
  requirements: { sf_method: post }
哈维

category_set_representative_image:
  url:     /rappresentativa/:id
  param:  { module: category_new, action: setRepresentativeImage}
  class:   sfDoctrineRoute
  options: { model: Category, type: object }
  requirements: { sf_method: post }