Question

I'd like to set a variable in my Symfony action that holds the rendered template data for that action. I'm returning some JSON content with the action, and I'd like to store what the action would be outputting into the JSON and return it.

public function executeAjaxPriceAdditionCreate(sfWebRequest $request)
{
    $this->form = new ProductPriceAdditionAjaxForm();

    $json['success'] = $this->processAjaxPriceAdditionForm($request, $this->form);
    $this->setTemplate('ajaxPriceAdditionNew');
    $json['content'] = ???; // THIS IS WHERE THE RENDERED TEMPLATE CONTENT SHOULD GO.

            $this->getResponse()->setHttpHeader('Content-Type','application/json; charset=utf-8');
    return $this->renderText(json_encode($json));
}
Was it helpful?

Solution 2

What I ended up doing was using a flash instead of trying to send JSON. The template of the AJAX content tried to detect the flash at the top, and if so, it did the "success" methods (closing the modal pop-up box).

OTHER TIPS

If you name your template as a partial, you can use

$json['content] = $this->getPartial('ajaxPriceAdditionNew');

See getPartial API

exit($this->getPartial('ajaxPriceAdditionNew'));

// apps/frontend/modules/community/templates/_ajaxPriceAdditionNew.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top