0

我想在我的 Symfony 操作中设置一个变量,以保存该操作的渲染模板数据。我正在返回一些带有动作的 JSON 内容,我想将动作输出的内容存储到 JSON 中并将其返回。

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));
}
4

3 回答 3

2

如果您将模板命名为部分模板,则可以使用

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

请参阅getPartial API

于 2009-06-01T17:08:53.940 回答
0

我最终做的是使用闪存而不是尝试发送 JSON。AJAX 内容的模板尝试检测顶部的 flash,如果是,则执行“成功”方法(关闭模态弹出框)。

于 2009-05-31T16:23:52.023 回答
0
exit($this->getPartial('ajaxPriceAdditionNew'));

// apps/frontend/modules/community/templates/_ajaxPriceAdditionNew.php
于 2010-10-17T21:51:09.920 回答