CI Framework Integration Smarty Steps detailed _php Example

Source: Internet
Author: User
Tags autoload codeigniter smarty template zend framework

In this paper, the Smarty Steps of CI framework integration are described in detail. Share to everyone for your reference, specific as follows:

CI combined with smarty configuration steps:

1. The first step is to configure CI and download Smarty templates personally like to use this version (Smarty-3.1.8).

2. The second part of the download to the Smarty version of the release and then Libs file renamed to Smarty and then copy this file to the Ci\application\libraries directory below

3. Create a file under the Ci\application\libraries directory, the filename can be customized, for example, see a tp.php document.

4. Open tp.php with the compiler and write the following code:

<?php
if (! defined (' BasePath ')) exit (' No Direct script access allowed ');
Require_once (' smarty/smarty.class.php ');
Class TP extends smarty{
 function tp () {
  parent::smarty ();
  $this->template_dir = apppath. ' Views ';
  $this->compile_dir = AppPath. ' templates_c/';
  $this->left_delimiter = ' <{';
  $this->right_delimiter = '}> ';
 }
}

5. In the establishment of a Ci\application\templates_c folder

6. Open the ci\application\config\autoload.php file

$autoload [' libraries '] = array ();

Change into:

$autoload [' libraries '] = Array (' database ', ' TP ');

OK our configuration has been successful here, and then we start to test

The first step in testing is to establish a controller:

1. Create a file named ceshi.php under \application\controllers, file contents

<?php
if (! defined (' BasePath ')) exit (' No Direct script access allowed ');
Class Home extends Ci_controller {
  function __construct ()
  {
   parent::__construct ();
   $this->load->helper (' url ');
   $this->tp->assign (' Base_url ', Base_url ());
   Define CSS and JS path
  }
  function Index ()
  {
   $this->tp->assign ("title"), "Congratulations on your Smarty installation success!" ");
   $this->tp->assign ("Body", "Welcome to use Smarty template Engine");
   $arr = Array (1=> ' Zhang ',2=> ' Xing ',3=> ' Wang ');
   $this->tp->assign ("MyArray", $arr);
   $this->tp->display (' ceshi.html ');
  }


2. Create template files in the Ci\application\views directory to create a file named ceshi.html files, the contents of the file is

 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
 "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">
 
 

Finally enter the address Http://localhost/ci/application/index.php/ceshi (The idea CI represents you to place the root directory of the files in the CI frame) after you run, you will see the page where you configured Smarty to succeed, Here, the integration and testing of CI and Smarty are complete.

More interested in CodeIgniter related content readers can view the site topics: "Smarty Template Primer Tutorial", "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", " thinkphp Getting Started tutorial, thinkphp Common methods Summary, Zend Framework Framework Introduction Tutorial, PHP object-oriented Program Introduction tutorial, Php+mysql database operation Getting Started tutorial and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.