Codeigniter integration smarty

Source: Internet
Author: User

 

Codeigniter integrates smarty to separate view and code (root directory level)

 

 

 

Iapp/libraries/cismarty. php

 

 

<? PHP defined ('basepath') or die ('Access restricted! '); <Br/>/** <br/> * This is a smarty initialization class <br/> * @ author hs <br/> * @ date 2010-8-12 <br/> *@ version dir <br/> */<br/> require (smartyroot. 'smarty. class '. EXT); <br/> // require (apppath. 'libraries/smarty. class '. EXT ); // apppath is the application directory defined in the entry file. <br/> class cismarty extends smarty <br/>{< br/>/** <br/> * constructor <br /> * @ access public <br/> * @ Param array/string $ template_dir <br/> * @ return OBJ smarty OBJ <Br/> */<br/> public function _ construct ($ template_dir = '') //, $ compile_dir ='', $ config_dir = '', $ cache_dir = '') <br/>{< br/> $ this-> smarty (); <br/> If (is_array ($ template_dir )) <br/>{< br/> foreach ($ template_dir as $ key => $ value) <br/>{< br/> $ this-> $ key = $ value; <br/>}< br/> else <br/>{< br/> $ this-> template_dir = $ template_dir? $ Template_dir :( root. '/template'); <br/>}< br/> // $ this-> compile_dir = $ compile_dir? $ Compile_dir: Root. '/templates_c'; <br/> // $ this-> config_dir = $ config_dir? $ Config_dir: Root. '/config'; <br/> // $ this-> cache_dir = $ cache_dir? $ Cache_dir: Root. '/cache'; <br/> $ this-> caching = true; <br/> $ this-> cache_lifetime = 120; <br/> $ this-> left_delimiter = "{*"; // filter JS <br/> $ this-> right_delimiter = "*}"; <br/>}< br/>} 

IWeb/index. php, codeigniter's core ilibrary is also at the same level as iapp and iWeb

<? Php <br/> session_start (); <br/>/* <br/> | --------------------------------------------------------------- <br/> | PHP Error Reporting level <br/> | by default runs with error reporting set to all. for security <br/> | reasons you are encouraged to change this when your site goes live. <br/> | for more info visit: http://www.p Hp.net/error_reporting <br/> | <br/> */<br/>/* start */<br/> error_reporting (e_all ); <br/> // set_time_limit (1000); <br/> ini_set ('memory _ limit ', '12m'); <br/> ini_set ('display _ errors ', 'on'); <br/> ini_set ('html _ errors ', 'on '); <br/>/* end */<br/> date_default_timezone_set ('prc'); <br/> define ('ds', directory_separator ); // 2010.8.12 <br/> define ('root', dirname (_ file _); // 2010.8.12 <br/> define ('smartyroot', Dir Name (dirname (_ file __)). DS. 'smarty/'); // 2010.10.29 <br/> define ('dshtml ',". html "); // 2010.8.12 <br/>/* <br/> | used <br/> | system folder name <br/> | used <br/> | this variable must contain the name of your "system" folder. <br/> | include the path if the folder is not in the same d Irectory <br/> | as this file. <br/> | no trailing slash! <Br/> | <br/> */<br/> $ system_folder = "ilibrary "; <br/>/* <br/> | recommend <br/> | application folder name <br/> | recommend <br/> | if you want this front Controller to use a different "application" <br/> | folder then the default one you can set its name here. the folder <br/> | can also be Renamed Or relocated anywhere on your server. <br/> | for more info please see the User Guide: <br/> | http://codeigniter.com/user_guide/general/managing_apps.html <br/> | no trailing slash! <Br/> | <br/> */<br/>/* $ application_folder = "application"; */<br/> $ application_folder = "iapp "; <br/>/* <br/> | ========================== =========================================< br/> | End of user retriable Settings <br/> | ==================================== ===================================< br/> */<br />/* <br/> | ------------------------------------------------------------- <br/> | set the server path <br/> | Reset <br/> | Let's attempt to determine the full-server path to the "System" <br/> | folder in order to reduce possibility of Path Problems. <br/> | Note: We only attempt this if the user hasn't specified a <br/> | full server path. <br/> | <br/> */<br/>/* If (strpos ($ system_folder, '/') = false) <br/>{< br/> If (function_exists ('R Ealpath') and @ realpath (dirname (_ file __))! = False) <br/>{< br/> $ system_folder = realpath (dirname (_ file __)). '/'. $ system_folder; <br/>}< br/> else <br/> {<br/> // swap directory separators to UNIX style for consistency <br/> $ system_folder = str_replace ("//", "/", $ system_folder); <br/>}*/<br/> $ system_folder = dirname (_ file __)). DS. $ system_folder; <br/>/* <br/> | statement <br/> | define application constants <br/> | statement <br/> | ext-the file extension. typically ". PHP "<br/> | self-the name of this file (typically" index. PHP ") <br/> | fcpath-the full server path to this file <br/> | basepath-the full server path to the "System" folder <br/> | apppath-the full server Path to the "application" folder <br/> | <br/> */<br/> define ('text ', '. PHP '); <br/> define ('self', pathinfo (_ file __, pathinfo_basename); <br/> define ('fcpath ', str_replace (self, '', _ file _); <br/> define ('basepath', $ system_folder. '/'); <br/>/* <br/> If (is_dir ($ application_folder) <br/>{< br/> define ('apppath ', $ application_folder. '/'); <br/>}< br/> else <br/> {<br/> if ($ application_folder = '') <br/>{< br/> $ application_folder = 'application'; <br/>}< br/> define ('appath', basepath. $ application_folder. '/'); <br/>}< br/> */<br/> define ('apppath', dirname (_ file __)). DS. $ application_folder.ds ); <br/>/* <br/> | ------------------------------------------------------------- <br/> | load the Front Controller <br/> | weight <br/> | and away we go... <br/> | <br/> */<br/> // echo basepath. 'codeigniter/codeigniter '. EXT; <br/> require_once basepath. 'codeigniter/codeigniter '. EXT; <br/>/* End of file index. PHP */<br/>/* location :. /index. PHP */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.