Codeingiter 2.2.x and smarty3 integration solution to solve CI Deficiency

Source: Internet
Author: User
Tags autoload codeigniter


Currently, the CI framework is available in version 2.0. I always wanted to try the core of my novel website.

I searched my website in China and found no such information. As long as I look for e-wen's website, I still find it. After testing, it can be used normally, on a website called cool PHP tool. The author provides the configuration scheme and the configured files, but Xilin always fails according to his writing steps. Later, I carefully read the file and found that, the friend mistaken the directory when packaging the file.

Next I will give you a detailed description of the configuration steps.

Step 1: Install codeingiter. This does not need to be detailed, for: http://codeigniter.com/downloads/

Step 2: download the latest version of smarty library,: http://www.smarty.net/download

Step 3: Download the configuration file package. The smarty configuration scheme has been written in it. You can reconfigure it according to your own needs. : Codeigniter-smarty-3.zip(12.46 kb, downloads: 591)

Step 4: Create a libs directory under the system directory, and then create a smarty directory under the libs directory. The structure is as follows:

[This step is tested and directly stored in the project directory. For example, in application/libraries/smarty, write a class library in step 5, and then automatically load the file]

System/libs/smarty


Then, put the smarty class library file in the above smarty directory.

Step 5: copy the files in the codeigniter-smarty-3.zip package to the corresponding folder under the root directory. Then create the smarty class library fileSmarty. php. The Code is as follows:

PHP Copy code<? PHP if (! Defined ('basepath') Exit ('no direct Script Access allowed ');
 
/**
* Smarty class
*
* @ Package codeigniter
* @ Subpackage Libraries
* @ Category smarty
* @ Author Kepler gelotte
* @ Link http://www.coolphptools.com/codeigniter-smarty
*/
 
Require_once (basepath. 'libs/smarty/libs/smarty. Class. php ');
 
Class ci_smarty extends smarty {
 
Function ci_smarty (){
Parent: smarty ();
 
$ This-> compile_dir = apppath. "views/templates_c ";
$ This-> template_dir = apppath. "views/templates ";
$ This-> assign ('apppath', apppath );
$ This-> assign ('basepath', basepath );
 
Log_message ('debug', "smarty class initialized ");
}
 
Function _ construct (){
Parent: :__ construct ();
 
$ This-> compile_dir = apppath. "views/templates_c ";
$ This-> template_dir = apppath. "views/templates ";
$ This-> assign ('apppath', apppath );
$ This-> assign ('basepath', basepath );
 
// Assign codeigniter object by reference to Ci
If (method_exists ($ this, 'assignbyref ')){
$ CI = & get_instance ();
$ This-> assignbyref ("Ci", $ CI );
}
Log_message ('debug', "smarty class initialized ");
}
 
/**
* Parse a template using the smarty Engine
* This is a convenience method that combines assign () and
* Display () into one step.
*
* Values to assign are passed in an associative array
* Name => value pairs.
* If the output is to be returned as a string to the caller
* Instead of being output, pass true as the third parameter.
*
* @ Access public
* @ Param string
* @ Param Array
* @ Param bool
* @ Return string
*/
 
Function view ($ template, $ DATA = array (), $ return = false ){
Foreach ($ data as $ key => $ Val ){
$ This-> assign ($ key, $ Val );
}
 
If ($ return = false ){
$ CI = & get_instance ();
$ Ci-> output-> final_output = $ this-> fetch ($ template); return;} else {return $ this-> fetch ($ template );}}} // end smarty class Copy code


Then save the file to the following directory:

Application/libraries/smarty. php


The directory in the original text is/system/application/libraries/smarty. php, but an error is reported here.

Step 6: Let the CI automatically load the smarty library each time. Open the/system/application/config/autoload. php file and add the smarty library name in $ autoload ['libraries'] as follows:

PHP Copy code$ Autoload ['libraries'] = array ('smarty '); Copy code


Finally, you can try the smarty library to work normally. The previous compressed package already contains the original test file. Test path:

Http: // your-site/index. php/Example

The correct results page is as follows:

Update Description: This error is often reported after the smarty environment is configured!

When this error occurs, open the libs/sysplugins/smarty_internal_data.php file and search$ _ VariableThe name of the variable. Most errors are written$ _ Variable. Delete the preceding $ symbol!

Codeingiter 2.2.x and smarty3 integration solution to solve CI Deficiency

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.