Symfony1 symfony:调用url_for()时出错<;脚本>;标签
我在这些javascript标记中调用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"); }
<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 }