0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.