Symfony: Problem loading component with AJAX
I try to load a component via AJAX in Symfony context.
I have created my link in my view:
<?php
echo jq_link_to_remote开发者_运维百科('Compétences', array(
'update' => 'right_column',
'url' => 'personnage/loadCompetences',
'position' => 'top',
));
?>
The action called:
public function executeLoadCompetences(sfWebRequest $request){
if ($request->isXmlHttpRequest())
$this->renderComponent("personnage", "competences");
}
And the component (controller + view _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>
But I can't load component if I don't define a loadCompetenceSuccess.php (which includes the component).
Is there a way to load a component without create a xxxSuccess.php view?
You're missing a return
in your action's code:
return $this->renderComponent("personnage", "competences");
Unless you return something, symfony assumes "Success", that's why it's looking for actionnameSuccess.php by default.
Also: instead of hardcoding image paths like that, have a look at the image_path
and image_tag
helpers.
精彩评论