且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 zf2 控制器中附加 css 和 javascript 文件?

更新时间:2023-09-10 21:11:28

空白页"仅表示正在生成错误,但您已关闭 display_errors.检查您的网络服务器错误日志以了解实际问题是什么(这也将帮助您调试未来的问题).

The 'blank page' just means an error is being generated but you have display_errors turned off. Check your web server error log to see what the actual problem is (this will help you debug future issues as well).

从查看您的代码来看,我猜问题出在对 $this->viewHelperManager 的调用上,因为没有这样的事情(除非您已将其设置在控制器).

From looking at your code, I'd guess the problem is with the calls to $this->viewHelperManager, as there is no such thing (unless you've set that elsewhere in your controller).

您可能想要:

$this->getServiceLocator()->get('viewhelpermanager')->get('headLink')->appendStylesheet('/css/style.css');

尽管如果您需要那么多视图助手调用,则可能值得将 headLink 助手作为依赖项传入.

although if you need that many view helper calls it might be worth passing the headLink helper in as a dependency.