CodeIgniterはsmarty 3を使用
1973 ワード
一.Smartyクラスライブラリを作成します.
1.smartyのlibsファイルをlibrariesにコピーします(ここではsmartyと名前を変更します)
2.新しいCismarty.phpファイル.(ファイル仕様、ファイル名の頭文字とclass名の頭文字は大文字ですが、コントローラリファレンスがロードされるとクラス名/ファイル名は大文字ではありません)
Cismarty.php
対応するディレクトリにsmartyのフォルダを新規作成します.templates,configs,cache,plugins,templates_c.
二.コントローラファイル.
コントローラファイルpaperを作成します.php(クラス名の頭文字大文字)(loadを使用してlibrariesをロードする場合はデフォルトでコンストラクタ関数を実行し、urlルーティングを使用してコントローラにアクセスする場合はコンストラクタ関数とデフォルトのindexメソッドを実行します.)
paper.php:
アプリケーション/config/autoloadでもよい.phpで自動ロードリソースを構成します.
1.smartyのlibsファイルをlibrariesにコピーします(ここではsmartyと名前を変更します)
2.新しいCismarty.phpファイル.(ファイル仕様、ファイル名の頭文字とclass名の頭文字は大文字ですが、コントローラリファレンスがロードされるとクラス名/ファイル名は大文字ではありません)
Cismarty.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH . 'libraries/smarty/Smarty.class.php');
//CI, index.php ,url 。
//BASEPATH - The full server path to the "system" folder
//APPPATH - The full server path to the "application" folder
class Cismarty extends Smarty
{
public function __construct()
{
parent::__construct();
$this->caching = false;
$this->setTemplateDir(APPPATH . 'views/Smarty/templates'); // 。
$this->setConfigDir(APPPATH . 'views/Smarty/configs'); // ,
$this->setCacheDir(APPPATH . 'views/Smarty/cache'); // , Smarty
$this->setPluginsDir(APPPATH . 'views/Smarty/plugins'); //
$this->setCompileDir(APPPATH . 'views/Smarty/templates_c'); // Smarty
}
}
?>
対応するディレクトリにsmartyのフォルダを新規作成します.templates,configs,cache,plugins,templates_c.
二.コントローラファイル.
コントローラファイルpaperを作成します.php(クラス名の頭文字大文字)(loadを使用してlibrariesをロードする場合はデフォルトでコンストラクタ関数を実行し、urlルーティングを使用してコントローラにアクセスする場合はコンストラクタ関数とデフォルトのindexメソッドを実行します.)
paper.php:
<?php
class Paper extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function pri_body()
{
$this->load->library('cismarty');
$this->cismarty->assign("name", 1200);
$this->cismarty->display('dd.tpl');
}
}
?>
アプリケーション/config/autoloadでもよい.phpで自動ロードリソースを構成します.