2011-06-05 67 views
0

我尝试在symfony上下文中通过AJAX加载组件。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

你在你的动作的代码所缺少一个return

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

除非你返回的东西,symfony的假设“成功”,这就是为什么它在找actionnameSuccess.php默认。

另外:而不是像这样的硬编码图像路径,看看image_pathimage_tag助手。