本文整理汇总了PHP中FOS\RestBundle\View\View::getTemplateVar方法的典型用法代码示例。如果您正苦于以下问题:PHP View::getTemplateVar方法的具体用法?PHP View::getTemplateVar怎么用?PHP View::getTemplateVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\RestBundle\View\View
的用法示例。
在下文中一共展示了View::getTemplateVar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareTemplateParameters
/**
* Prepares view data for use by templating engine.
*
* @param View $view
*
* @return array
*/
public function prepareTemplateParameters(View $view)
{
$data = $view->getData();
if ($data instanceof FormInterface) {
return array($view->getTemplateVar() => $data->getData(), 'form' => $data->createView());
}
if (empty($data) || !is_array($data) || is_numeric(key($data))) {
return array($view->getTemplateVar() => $data);
}
if (isset($data['form']) && $data['form'] instanceof FormInterface) {
$data['form'] = $data['form']->createView();
}
return $data;
}
示例2: prepareTemplateParameters
/**
* Prepares view data for use by templating engine.
*
* @param View $view
*
* @return array
*/
public function prepareTemplateParameters(View $view)
{
$data = $view->getData();
if ($data instanceof FormInterface) {
$data = [$view->getTemplateVar() => $data->getData(), 'form' => $data];
} elseif (empty($data) || !is_array($data) || is_numeric(key($data))) {
$data = [$view->getTemplateVar() => $data];
}
if (isset($data['form']) && $data['form'] instanceof FormInterface) {
$data['form'] = $data['form']->createView();
}
$templateData = $view->getTemplateData();
if (is_callable($templateData)) {
$templateData = call_user_func($templateData, $this, $view);
}
return array_merge($data, $templateData);
}
示例3: prepareTemplateParameters
/**
* Prepare view data for use by templating engine.
*
* @param View $view
*
* @return array
*/
public function prepareTemplateParameters(View $view)
{
$data = $view->getData();
if (empty($data)) {
return array($view->getTemplateVar() => $data);
}
if (!is_array($data)) {
$data = array($view->getTemplateVar() => $data);
}
foreach (array_keys($data) as $key) {
if ($data[$key] instanceof FormInterface) {
$data[$key] = $data[$key]->createView();
}
}
if (is_numeric($key)) {
$data = array($view->getTemplateVar() => $data);
}
return $data;
}