2013-03-01 98 views
0

我開始使用笨框架,我想用菲爾鱘魚的笨模板:如何使用philsturgeon Codeigniter模板?

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

我也跟着像下面的安裝步驟:

  1. 下載最新版本的
  2. 將此包中的文件複製到應用程序文件夾中的相應文件夾中
    • 從012複製到相應的地方(在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中,I h AVE layouts\default.php,我寫

{{ template:title }} 

。在default.php。 但我無法訪問標題變量。我做錯了什麼,或者不行? 我在default.php中添加了我可以使用$ template ['title']的這一節,但是我不能使用解析器來顯示我的變量。

+1

我已經對您的問題進行了相當多的修改,請查看[版本歷史記錄](http://stackoverflow.com/posts/15153889/revisions)以查看我如何使用格式,並將其作爲未來的指南。 – 2013-03-01 09:02:53

+0

感謝Tim的編輯 – aya 2013-03-01 09:10:43

回答

1
  1. 將Template.php文件複製到您下載的軟件包的庫文件夾中。

  2. 複製的template.php文件config文件夾

  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; 
    

這是基本配置,如果您想要了解如何從視圖發送數據的更多信息,請告知我

+0

感謝MDeSilva,這個答案對誰不能安裝模板很有用。我可以使用$ template訪問我的變量(例如'echo $ template ['title'];'),但我無法使用解析器方式訪問。非常感謝。 – aya 2013-03-01 12:42:09

+0

解決我的錯誤謝謝 – aya 2013-04-01 10:04:46