2011-06-05 69 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助手。