可以在变量中获取Phalcon\Mvc\View渲染输出吗?

ava*_*sin 4 php view phalcon

我需要回放json对象,它具有带有渲染动作的属性'html'.是否有可能与Phalcon本地人一起做?

例:

$posts = NewsPost::find(['limit' => 10]);
$view = new Phalcon\Mvc\View();
$view->setVar('posts', $posts);
$view->setMainView('news/posts'); // not sure if this is correct

// retrieve some data ...
$response = [
    'html' => $view->render(),
    'somedata' => 'somevalues',
    ....
];
Run Code Online (Sandbox Code Playgroud)

有关phalcon php框架的PS问题:http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_View.html

twi*_*tra 7

需要首先启动输出缓冲:

$view = new Phalcon\Mvc\View();

$view->setVar('posts', $posts);

$view->start();
$view->render(); //Pass a controller/action as parameters if required
$view->finish();

// retrieve some data ...
$response = [
    'html' => $view->getContent(),
    'somedata' => 'somevalues',
    ....
];
Run Code Online (Sandbox Code Playgroud)