我在 zend Controller 中附加了一些样式表,但显示空白页面,我如何在 zend Controller 中包含样式表和 javascript 文件?这是我的代码:
public function showAction()
{
//css
$this->viewHelperManager->get('headLink')->appendStylesheet('/css/style.css');
$this->viewHelperManager->get('headLink')->appendStylesheet('/css/bootstrap-theme.min.css');
$this->viewHelperManager->get('headLink')->appendStylesheet('/css/tweaks.css');
$this->viewHelperManager->get('headLink')->appendStylesheet('/css/fullcalendar.css');
$this->viewHelperManager->get('headLink')->appendStylesheet('/css/fullcalendar.print.css');
$this->viewHelperManager->get('headLink')->appendStylesheet('/css/jquery-ui.min.css');
$this->viewHelperManager->get('headLink')->appendStylesheet('/css/jquery.simple-dtpicker.css');
//js
$this->viewHelperManager->get('headScript')->appendFile('/admin_static/js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js');
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('calendar', array(
'action' => 'create'
));
}
$calendar = $id;
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$eventshow = $dm->createQueryBuilder('Calendar\Document\Calendar')
->hydrate(false)
->field("id")->equals($id)
->getQuery()->execute();
$array = array();
if($eventshow && !is_null($eventshow) && is_object($eventshow)){
foreach($eventshow as $key=>$value) {
$array[] = array(
'calendar_id' => $value['_id'],
'user_id' => $value['user_id'],
'title' => $value['title'],
'description' => $value['description'],
);
}
}
return array('calendar' => $calendar , 'calendardata' => $array);
}
最佳答案
“空白页”仅表示正在生成错误,但您已关闭 display_errors
。检查您的网络服务器错误日志以了解实际问题是什么(这也将帮助您调试 future 的问题)。
从你的代码来看,我猜问题出在对 $this->viewHelperManager
的调用上,因为没有这样的东西(除非你在 Controller 的其他地方设置了它) )。
您可能想要:
$this->getServiceLocator()->get('viewhelpermanager')->get('headLink')->appendStylesheet('/css/style.css');
尽管如果您需要那么多 View 帮助程序调用,则可能值得将 headLink 帮助程序作为依赖项传递。
关于javascript - 如何在 zf2 Controller 中附加 css 和 javascript 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23271745/