How to implement CI integrated smarty

Source: Internet
Author: User

Advice to a new partner: don't think about how complicated it is, see it again and you'll get it!

What is the purpose of this integration?

Because I have used CI and smarty, so I will say according to their own understanding: The CI framework in the controller, models aspects of doing very well, but in the changeable view I feel that there is no special handling of the view of the Smarty template to do well, so I thought of merging the two, take their long.

1, download the CI framework, smarty template, this will not need me to say more.

2, the Smarty Libs folder copy to the CI third_party folder (in fact, the copy to which folder is irrelevant, as long as the load to it on the line ), and renamed to Smarty;

3. Create a folder in the root directory of CI:

Also, create the smartyplu folder under the CI's Helpers folder

4. Create the smarty.php configuration file under the Configuration folder config of CI and copy the following code into it:

<?php  if (! defined (' BasePath ')) exit (' No Direct script access allowed ');//Specify the relevant folder $config[' Template_dir ']    = APPPATH. ' Views '; $config [' compile_dir ']     = Fcpath. ' Templates_c '; $config [' config_dir ']      = Fcpath. ' Configs '; $config [' cache_dir ']       = Fcpath. ' Cache '; $config [' plugins_dir ']     = APPPATH. ' Helpers/smartyplu ';//$config [' template_ext ']    =;//set cache, default = False$config[' caching ']         = false; $config [' Cache_lifetime ']  =: $config [' auto_literal ']    = false; $config [' left_delimiter ']  = ' <{'; $config [' Right_delimiter '] = '}> ';

5. Create the csmarty.php file in the Libraries folder of CI and copy the following code into it:

<?php if (! defined (' BasePath ')) exit (' No Direct script access allowed '); Require_once (APPPATH. ' Third_party/smarty/smarty.class.php ');//Specify the storage location of the Smarty.class.php hereClass Csmarty extends smarty{protected $CI;p ublic function __construct () {$this->ci = & Get_instance (); $this Ci->load->config (' Smarty ');//Load the Smarty configuration information file hereRelated configuration Item $this->template_dir = $this->ci->config->item (' Template_dir '); $this->compile_dir = $this-&gt ; Ci->config->item (' Compile_dir '); $this->config_dir = $this->ci->config->item (' Config_dir '); $ This->cache_dir = $this->ci->config->item (' Cache_dir '); $this->plugins_dir = $this->ci->conf Ig->item (' Plugins_dir ');//$this->template_ext = $this->ci->config->item (' Template_ext '); $this- >caching = $this->ci->config->item (' caching '); $this->cache_lifetime = $this->ci->config->        Item (' Cache_lifetime '); $this->auto_literal = $this->ci->config->item (' auto_literal ');        $this->left_delimiter = $this->ci->config->item (' Left_delimiter ');        $this->right_delimiter = $this->ci->config->item (' Right_delimiter ');        Set the encoding format and time zone header ("Content-type:text/html;charset=utf-8"); Date_default_timezone_set (' UTC ');}}

6, the start of Smarty added to the CI self-boot file autoload.php file:

$autoload [' libraries '] = Array (' Csmarty ');

7, Next is used in CI, will be in CI through $this->load->view ("index", $data) mode load view changed to Smarty Way:

$this->csmarty->assign (' data ', $data); $this->csmarty->display (' index.html ');

PS: When using the Smarty method, there are some problems on the path.

How to implement CI integrated smarty

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.