如何在每个页面中加载 CodeIgniter 帮助程序?
我有一个视图 header.php,它被加载到各种控制器方法中。它包含我的打开 html 标签、相关链接的基本标签以及我在应用程序的每个页面中调用的一些元标签。有没有办法加载渲染元标记和基本 url 的帮助程序,以便每次加载 header.php 时都可以使用它们,而不必包含 $this->load->helper('html' );
和 $this->load->helper('url');
每次我 $this->load->view('templates/标题', $data);
在控制器中加载 header.php?
I have a view, header.php, that gets loaded in various controller methods. It contains my opening html tag, a base tag for my relative links, and some meta tags that I call in every page of my application. Is there way to load the helpers that render the meta tags and base url so that they are available to header.php every time it is loaded without having to include $this->load->helper('html');
and $this->load->helper('url');
every time I $this->load->view('templates/header', $data);
in a controller to load header.php?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您经常需要这些,您应该将它们添加到您的助手自动加载中:
在 /application/config/autoload.php 在第 93 行左右,更改
为
然后,它们会在每个请求上加载。
If you're needing these that often, you should just add those to your helpers autoload:
In /application/config/autoload.php around line 93, change
to
Then, they're loaded on every request.
很简单,将它们添加到自动加载文件中。这样,您就可以从任何文件访问它们,并且您不必调用它们。
Simple, add them to the autoload file. That way they'll be accessible from any file, and you won't ever have to call those.