danieltorscho / ci_template_lib
简单模板库,包含一些核心功能,可简化CodeIgniter 2.x的开发过程
Requires
- php: >=5.2.4
This package is not auto-updated.
Last update: 2023-01-16 23:28:48 UTC
README
简单模板库,包含一些核心功能,可简化CodeIgniter 2.x的开发过程。
如何使用
- 将所有文件解压到您的项目根目录。如果提示,请确保覆盖所有文件。
- 打开
app/config/autoload.php
,将'template'
添加到$autoload['libraries']
和$autoload['config']
。 - 编辑您的模板配置文件
application/config/template.php
。 - 导航到
yourwebsite.dev/index.php/welcome
。
模板库会自动处理大部分视图逻辑。
在控制器方法内部调用简单的 $this->template->load();
,它将自动创建 pagetitle
、pagename
、scripts
、stylesheets
变量,并在 load()
函数中没有提供任何内容的情况下,自动加载相应的子视图文件 controller/method.php
。
文档
加载自定义视图文件
$this->template->load('path/to/view.php');
在自定义模板文件中加载自定义视图文件
$this->template->load('template/login', 'user/login/form');
设置自定义页面标题
$this->template->title('产品页面');
设置自定义面包屑
$this->template->crumb('电子商务', 'ecommerce/index');
$this->template->crumb('产品', 'ecommerce/products');
$this->template->crumb('产品 #391');
添加自定义JavaScript文件加载
$this->template->script('plugin/head.js', TRUE)
$this->template->script('footer.js');
添加自定义CSS文件加载
$this->template->css('print.css', 'print');
设置自定义变量
$this->template->set_item('articles', $articles);
// 现在您可以在所有子视图中使用 $articles