ci框架学习中注意的事项

 

视图:

加载视图:$this->load->view('name'); 

一次可以加载多个视图,如:

    public function index()
    {
        $data['page_title'] = 'Your title';
        $this->load->view('header');
        $this->load->view('menu');
        $this->load->view('content', $data);
        $this->load->view('footer');
    }

在子目录中存储视图: $this->load->view('directory_name/file_name');

辅助函数:

加载辅助函数:$this->load->helper('name');  name 参数为辅助函数的文件名,去掉 .php 文件后缀以及 _helper 部分。

 

加载多个辅助函数: $this->load->helper( array('helper1', 'helper2', 'helper3') );

注意也可以自动加载,放在autoload配置中。

使用 CodeIgniter 类库,所有的系统类库都位于 system/libraries/ 目录下,大多数情况下,在使用之前, 你要先在 控制器 中初始化它

单个:$this->load->library('class_name');  或 多个:$this->load->library(array('email', 'table'));

 

使用 CodeIgniter 驱动器:

驱动器位于 system/libraries/ 目录,每个驱动器都有一个独立的目录,目录名和 驱动器父类的类名一致,在该目录下还有一个子目录,命名为 drivers,用于存放 所有子类的文件

初始化: $this->load->driver('class_name'); 例如:
$this->load->driver('some_parent');
$this->some_parent->some_method();

而对于那些子类,我们不用初始化,可以直接通过父类调用了:

$this->some_parent->child_one->some_method();
$this->some_parent->child_two->another_method();
注意:为了在大小写敏感的文件系统下保证兼容性,Driver_name 目录必须以 ucfirst() 函数返回的结果格式进行命名。

 网页缓存:

将下面的代码放到任何一个控制器的方法内,你就可以开启缓存了:

开启缓存:$this->output->($n);其中 $n 是缓存更新的时间(单位分钟),

注意:由于 CodeIgniter 存储缓存的方式,只有通过 view 输出的页面才能缓存;如果你修改了可能影响页面输出的配置,你需要手工删除掉 你的缓存文件。

删除缓存:删除缓存代码之后并不是立即生效,必须等到缓存过期才会生效)

// Deletes cache for the currently requested URI

$this->output->delete_cache();

// Deletes cache for /foo/bar

$this->output->delete_cache('/foo/bar');

 
 

posted on   andydaopeng  阅读(327)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2014-11-25 php使用技巧--之链接地址
2014-11-25 PHP做好防盗链的基本思想 防盗链的设置方法

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示