symfony:使用AJAX加载组件时遇到问题

时间:2011-06-05 09:02:15

标签: jquery ajax symfony1 components

我尝试在symfony上下文中通过AJAX加载组件。

我在视图中创建了我的链接:

<?php
    echo jq_link_to_remote('Compétences', array(
        'update'   => 'right_column',
        'url'      => 'personnage/loadCompetences',
        'position' => 'top',
    ));
?>

该行动称为:

public function executeLoadCompetences(sfWebRequest $request){
    if ($request->isXmlHttpRequest())
         $this->renderComponent("personnage", "competences");   
}

组件(控制器+视图_competence.php

public function executeCompetences(sfWebRequest $request){
        $personnage = $this->getUser()->getGuardUser()->Personnage;

        $this->lecture = $personnage->getCom_lecture();
        $this->ecriture = $personnage->getCom_ecriture();
        $this->armes = $personnage->getCom_armes();
        $this->bouclier = $personnage->getCom_bouclier();
        $this->diplomatie = $personnage->getCom_diplomatie();
        $this->commandement = $personnage->getCom_commandement();
        $this->meditation = $personnage->getCom_meditation();
        $this->embuscade = $personnage->getCom_embuscade();
        $this->herboristerie = $personnage->getCom_herboristerie();
        $this->espionnage = $personnage->getCom_espionnage();
}


<div id="subpanel">
    <ul id="competences">
        <li class="competence">
            <span>Lecture</span>
            <img alt="" src="/medieval-ages-v2/web/images/competences/competences_<?php echo $lecture ?>.png" />
        </li>
    ...
    </ul>
</div>

但如果我没有定义loadCompetenceSuccess.php(包括组件),我就无法加载组件。

有没有办法在不创建xxxSuccess.php视图的情况下加载组件?

1 个答案:

答案 0 :(得分:1)

您在操作代码中遗漏了return

return $this->renderComponent("personnage", "competences");

除非您返回某些内容,否则symfony会假定“成功”,这就是为什么默认情况下它正在寻找actionnameSuccess.php。

另外:不要像这样对图像路径进行硬编码,而是查看image_pathimage_tag助手。