• 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');

     
     
  • 相关阅读:
    [BZOJ3694]最短路
    [Usaco2011 Jan]道路和航线
    洛谷P1443马的遍历
    洛谷P1636学画画
    洛谷P1605走迷宫
    队列&广搜
    数论卷积公式and莫比乌斯反演
    数学之判断素数
    纯数学篇之欧拉定理证明
    筛素数
  • 原文地址:https://www.cnblogs.com/andydao/p/4994828.html
Copyright © 2020-2023  润新知