CodeIgniter整合smarty

 

CodeIgniter整合smarty,实现view与代码分离(根目录平级)

 

 

 

iapp/libraries/CISmarty.php

 

 

<?php defined('BASEPATH') or die('Access restricted!'); /** * 这是一个smarty的初始化类 * @author hs * @date 2010-8-12 * @version dir */ require(SMARTYROOT.'Smarty.class'.EXT); //require(APPPATH.'libraries/smarty/Smarty.class'.EXT);//APPPATH是入口文件定义的application的目录 class Cismarty extends Smarty { /** * 构造函数 * @access public * @param array/string $template_dir * @return obj smarty obj */ public function __construct($template_dir = '')//, $compile_dir = '', $config_dir = '', $cache_dir = '') { $this->Smarty(); if(is_array($template_dir)) { foreach ($template_dir as $key => $value) { $this->$key = $value; } } else { $this->template_dir = $template_dir ? $template_dir :(ROOT . '/template'); } // $this->compile_dir = $compile_dir ? $compile_dir : ROOT . '/templates_c'; // $this->config_dir = $config_dir ? $config_dir : ROOT . '/config'; // $this->cache_dir = $cache_dir ? $cache_dir : ROOT . '/cache'; $this->caching =true; $this->cache_lifetime =120; $this->left_delimiter ="{*"; //过滤JS $this->right_delimiter ="*}"; } } 

iweb/index.php, CodeIgniter 的核心ilibrary也与iapp,iweb平级

<?php session_start(); /* |--------------------------------------------------------------- | PHP ERROR REPORTING LEVEL |--------------------------------------------------------------- | | By default CI runs with error reporting set to ALL. For security | reasons you are encouraged to change this when your site goes live. | For more info visit: http://www.php.net/error_reporting | */ /*start*/ error_reporting(E_ALL); //set_time_limit(1000); ini_set('memory_limit','512M'); ini_set('display_errors','On'); ini_set('html_errors','On'); /*end*/ date_default_timezone_set('PRC'); define('DS', DIRECTORY_SEPARATOR);//2010.8.12 define('ROOT',dirname(__FILE__));//2010.8.12 define('SMARTYROOT',dirname(dirname(__FILE__)).DS.'smarty/');//2010.10.29 define('DSHTML',".html");//2010.8.12 /* |--------------------------------------------------------------- | SYSTEM FOLDER NAME |--------------------------------------------------------------- | | This variable must contain the name of your "system" folder. | Include the path if the folder is not in the same directory | as this file. | | NO TRAILING SLASH! | */ $system_folder = "ilibrary"; /* |--------------------------------------------------------------- | APPLICATION FOLDER NAME |--------------------------------------------------------------- | | If you want this front controller to use a different "application" | folder then the default one you can set its name here. The folder | can also be renamed or relocated anywhere on your server. | For more info please see the user guide: | http://codeigniter.com/user_guide/general/managing_apps.html | | | NO TRAILING SLASH! | */ /*$application_folder = "application";*/ $application_folder="iapp"; /* |=============================================================== | END OF USER CONFIGURABLE SETTINGS |=============================================================== */ /* |--------------------------------------------------------------- | SET THE SERVER PATH |--------------------------------------------------------------- | | Let's attempt to determine the full-server path to the "system" | folder in order to reduce the possibility of path problems. | Note: We only attempt this if the user hasn't specified a | full server path. | */ /*if (strpos($system_folder, '/') === FALSE) { if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE) { $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder; } } else { // Swap directory separators to Unix style for consistency $system_folder = str_replace("//", "/", $system_folder); }*/ $system_folder=dirname(dirname(__FILE__)).DS.$system_folder; /* |--------------------------------------------------------------- | DEFINE APPLICATION CONSTANTS |--------------------------------------------------------------- | | EXT - The file extension. Typically ".php" | SELF - The name of THIS file (typically "index.php") | FCPATH - The full server path to THIS file | BASEPATH - The full server path to the "system" folder | APPPATH - The full server path to the "application" folder | */ define('EXT', '.php'); define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); define('FCPATH', str_replace(SELF, '', __FILE__)); define('BASEPATH', $system_folder.'/'); /* if (is_dir($application_folder)) { define('APPPATH', $application_folder.'/'); } else { if ($application_folder == '') { $application_folder = 'application'; } define('APPPATH', BASEPATH.$application_folder.'/'); } */ define('APPPATH',dirname(dirname(__FILE__)).DS.$application_folder.DS); /* |--------------------------------------------------------------- | LOAD THE FRONT CONTROLLER |--------------------------------------------------------------- | | And away we go... | */ //echo BASEPATH.'codeigniter/CodeIgniter'.EXT; require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; /* End of file index.php */ /* Location: ./index.php */

你可能感兴趣的:(CodeIgniter整合smarty)