【问题标题】:How do I use the philsturgeon Codeigniter template?如何使用 philsturgeon Codeigniter 模板?
【发布时间】:2013-03-01 08:56:12
【问题描述】:

我开始使用 Codeigniter 框架,我想使用 Phil Sturgeon 的 Codeigniter 模板:

http://github.com/philsturgeon/codeigniter-template/zipball/master

我按照下面的安装步骤:

  1. 下载最新版本
  2. 将此包中的文件复制到应用程序文件夹中的相应文件夹
    • config/template复制到相应的位置(在config目录中)
    • libraries/template 复制到相应的位置(在库目录中。)
    • 加载模板(在config/autoload.php$this->load->library('template');

最后我在控制器中使用这个模板,如下所示:

public function index() {
  $data["header"] = "ayastr"; 
  $data["content"] = "content1"; 
  $this->template->enable_parser(TRUE);
  $this->template->enable_parser_body(TRUE); 
  //$this->template->set('title', "test");
  $this->template->title("aya"); 
  $this->template->build('example_page_view', $data);
 }

在视图example_page_view.php,我有layouts\default.php,我写了

{{ template:title }}

.. 在default.php. 但我无法访问 title 变量。我做错了什么,或者没有做什么? 我添加了这个部分,我可以在 default.php 中使用 $template['title'] 但我不能使用解析器来显示我的变量。

【问题讨论】:

  • 我对您的问题进行了大量修改,请查看version history 了解我是如何使用格式的,并在以后将其作为指南。
  • 感谢蒂姆的编辑

标签: php codeigniter templates


【解决方案1】:
  1. 将 Template.php 文件从您下载的包中复制到库文件夹中。

  2. 将 template.php 文件复制到配置文件夹

  3. 视图/模板下有模板吗

  4. 如下编辑template.php(配置文件)

    //Default Template Configuration (adjust this or create your own)
    //Default template - This is the Main template
    
    $template['default']['template'] = 'template/template';
    $template['default']['regions'] = array('menu','content','title');
    
    $template['default']['parser'] = 'parser';
    $template['default']['parser_method'] = 'parse';
    $template['default']['parse_template'] = TRUE;
    
    
    
    //Login Template
    $template['login']['template'] = 'template/template_login';
    $template['login']['regions'] = array('content');
    
    $template['login']['parser'] = 'parser';
    $template['login']['parser_method'] = 'parse';
    $template['login']['parse_template'] = TRUE;
    

这是基本配置,如果您想了解更多关于如何从视图发送数据的信息,请告诉我

【讨论】:

  • 感谢 MDeSilva ,这个答案对于无法安装模板的人很有用。我可以使用 $template 访问我的变量(例如echo $template['title'];),但我无法使用解析器方式访问。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2010-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-19
相关资源
最近更新 更多