本文整理汇总了PHP中Zend\View\Model\JsonModel::setCaptureTo方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonModel::setCaptureTo方法的具体用法?PHP JsonModel::setCaptureTo怎么用?PHP JsonModel::setCaptureTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\JsonModel
的用法示例。
在下文中一共展示了JsonModel::setCaptureTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRecursesJsonModelChildrenWhenRendering
/**
* @group 2463
*/
public function testRecursesJsonModelChildrenWhenRendering()
{
$root = new JsonModel(array('foo' => 'bar'));
$child1 = new JsonModel(array('foo' => 'bar'));
$child2 = new JsonModel(array('foo' => 'bar'));
$child1->setCaptureTo('child1');
$child2->setCaptureTo('child2');
$root->addChild($child1)->addChild($child2);
$expected = array('foo' => 'bar', 'child1' => array('foo' => 'bar'), 'child2' => array('foo' => 'bar'));
$test = $this->renderer->render($root);
$this->assertEquals(json_encode($expected), $test);
}
示例2: testChildrenMayInvokeDifferentRenderingStrategiesThanParents
public function testChildrenMayInvokeDifferentRenderingStrategiesThanParents()
{
$this->view->addRenderingStrategy(function ($e) {
$model = $e->getModel();
if (!$model instanceof ViewModel) {
return;
}
return new TestAsset\Renderer\VarExportRenderer();
});
$this->view->addRenderingStrategy(function ($e) {
$model = $e->getModel();
if (!$model instanceof JsonModel) {
return;
}
return new Renderer\JsonRenderer();
}, 10);
// higher priority, so it matches earlier
$this->result = $result = new stdClass();
$this->view->addResponseStrategy(function ($e) use($result) {
$result->content = $e->getResult();
});
$child1 = new ViewModel(array('foo' => 'bar'));
$child1->setCaptureTo('child1');
$child2 = new JsonModel(array('bar' => 'baz'));
$child2->setCaptureTo('child2');
$child2->setTerminal(false);
$this->model->setVariable('parent', 'node');
$this->model->addChild($child1);
$this->model->addChild($child2);
$this->view->render($this->model);
$expected = var_export(new ViewVariables(array('parent' => 'node', 'child1' => var_export(array('foo' => 'bar'), true), 'child2' => json_encode(array('bar' => 'baz')))), true);
$this->assertEquals($expected, $this->result->content);
}