如何在每个页面中加载CodeIgniter助手? [英] How do I load CodeIgniter helpers in every page?

查看:116
本文介绍了如何在每个页面中加载CodeIgniter助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,header.php,在各种控制器方法加载。它包含我的开始html标记,我的相对链接的基本标记,以及我在应用程序的每个页面调用的一些元标记。是否有方法加载渲染元标记和基本url的帮助,以便它们可用于header.php每次加载,而不必包括 $ this-> load-> helper 'html'); $ this-> load-> helper('url'); > $ this-> load-> view('templates / header',$ 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?

推荐答案

如果你经常需要这些,你应该将它们添加到你的helpers自动加载:

If you're needing these that often, you should just add those to your helpers autoload:

href =https://github.com/EllisLab/CodeIgniter/blob/develop/application/config/autoload.php> /application/config/autoload.php 第93行附近,更改

In /application/config/autoload.php around line 93, change

$autoload['helper'] = array();

$autoload['helper'] = array('html', 'url');

然后,在每个请求中加载它们。

Then, they're loaded on every request.

这篇关于如何在每个页面中加载CodeIgniter助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆