CodeIgniter Integrated smarty approach, codeignitersmarty_php tutorial

Source: Internet
Author: User
Tags autoload codeigniter zend framework

CodeIgniter Integrated smarty Approach, Codeignitersmarty


This paper describes the method of CodeIgniter integrated Smarty. Share to everyone for your reference, the specific steps are as follows:

1. Download Smarty

Extract the Libraries directory to CI such as:

ci/application/libraries/smarty-2.6.20

2. Writing mysmarty.php's own class library files

The code is as follows:

<?php if (!defined (' BasePath ')) exit (' No Direct script access allowed '); require "smarty-2.6.20/libs/ Smarty.class.php ";/*** @file system/application/libraries/mysmarty.php*/class Mysmarty extends smarty{function    Mysmarty () {$this->smarty ();    $config =& get_config (); Absolute path prevents "template not found" errors $this->template_dir = (!empty ($config [' Smarty_template_dir ']) ? $config [' Smarty_template_dir ']: basepath.    ' application/views/'); $this->compile_dir = (!empty ($config [' Smarty_compile_dir '])? $config [' Smarty_compile_dir ']: basepath.     ' cache/'); Use CI ' s cache folder if (function_exists (' Site_url ')) {//URL helper required $this->assign ("Site_url" , Site_url ()); So we can get the full path to CI easily}}/** * @param $resource _name String * @param $params array holds par  AMS that'll be passed to the template * @desc loads the template */function view ($resource _name, $params = Array ()) {if (STRPOS ($resource _name, '. ') = = = False) {$resource _name. = '. html '; } if (Is_array ($params) && count ($params)) {foreach ($params as $key = $value) {$this->ass      IGN ($key, $value);    }}//Check if the template file exists.    if (!is_file ($this->template_dir. $resource _name)) {show_error ("Template: [$resource _name] cannot be found.");  } return Parent::d isplay ($resource _name); }}//END class smarty_library?>

3. In autoload.php let CI automatically load Smarty

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

Or use a template to load your own smarty

$this->load->library ("Mysmarty");

4.smarty variable Assignment Display template

$this->mysmarty->assign (' Test ', ' Hello World '); $this->mysmarty->view (' Smarty ');

Note: External resource files such as images CSS are placed in the root directory of the CI system folder outside the website

Best used:

$this->load->helper (' url ');

Base_url () Visit:

Base_url (). " Images/xxx.jpg "

Don't put it in the system.

Add: small make up here to recommend a site of the PHP format beautification of the layout tools to help you in the future of PHP programming code layout:

PHP Code online format Beautification tool:

Http://tools.jb51.net/code/phpformat

In addition, because PHP is a C language style, the following tool can also be used to implement the PHP code format:

C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json

More interested in CodeIgniter related content readers can view this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP Excellent Development Framework Summary", "thinkphp Getting Started", " Summary of common methods of thinkphp, "Introduction to Zend Framework Frame", "Introduction to PHP Object-oriented Programming", "Introduction to Php+mysql Database Operation" and "PHP common database Operation Skills Summary"

It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.

http://www.bkjia.com/PHPjc/1133073.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133073.html techarticle CodeIgniter Integrated smarty approach, Codeignitersmarty This example describes CodeIgniter integration Smarty method. Share to everyone for your reference, the steps are as follows: 1. Download SM ...

  • 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.