我在这些javascript标签中调用url_for():
<script type="text/javascript">
$.post('<?php echo url_for('category_set_representative_image',
array('sf_subject' => $category)) ?>',
function(){
alert("fadsf");
}
);
</script>
但是我得到这个错误:
sfError404Exception: Empty module and/or action after parsing the URL
'/rappresentativa' (/).
我也有这样的路由规则:
category_set_representative_image:
url: /rappresentativa
param: { module: category_new, action: setRepresentativeImage }
class: sfDoctrineRoute
options: { model: Category, type: object }
注意:如果我在远端调用相同的url_for(),我不会有问题标签。
任何想法?
1.4科幻
杰维
上面描述的错误与script
标记无关。不管你在哪里使用它(url_for)
首先,我认为,您需要使用url_for(array('sf_route' => 'category_set_representative_image', 'sf_subject' => $category))
或仅url_for('category_set_representative_image', $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();
我认为这个问题只是与javascript和PHP之间引号的滥用有关。试试这样写:
<script type="text/javascript">
$.post('<?php echo url_for("category_set_representative_image",
array("sf_subject" => $category)) ?>',
function(){
alert("fadsf");
}
);
可以:
category_set_representative_image:
url: /rappresentativa
param: { module: category_new, action: setRepresentativeImage}
class: sfDoctrineRoute
options: { model: Category, type: object }
requirements: { sf_method: post }
EDIT:无论如何也是必要的antonkalyaev说:
category_set_representative_image:
url: /rappresentativa/:id
param: { module: category_new, action: setRepresentativeImage}
class: sfDoctrineRoute
options: { model: Category, type: object }
requirements: { sf_method: post }
杰维