ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Integrate Smarty Template Parsing into CodeIgniter

January 30, 2012 9:14pm

Subscribe [9]
  • #1 / Jan 30, 2012 9:14pm

    Aken

    2430 posts

    https://github.com/cryode/CodeIgniter_Smarty

    Visit the Github page to download the code and view the basic installation instructions.

    Also make sure to read the Smarty documentation for how to set up your view files to use Smarty features.

    v1.1.0—March 12, 2013

    - Smarty updated to version 3.1.13
    - New auto-escape variables feature
    - $ci global var changed to $CI
    - CI 3.0 VIEWPATH constant used, when available
    - Licensed properly!

    I like to use Smarty due for its templating context, rather than using PHP tags, as well as the ability to easily set up things like common header/footers, etc, without doing it in your controllers or other PHP areas.

    I’ve always used Smarty in a pretty basic way, so I haven’t integrated some of the fancier features quite yet. But I’m in the process of adding / playing / testing, and will continually add and/or optimize the code as I see fit.

    I don’t think I’ll need to do much support for this basic install, but if anyone has questions, please let me know. Also please suggest any features you might like, or bugs if you happen to spot one.

    Cheers!

  • #2 / Feb 19, 2012 3:41pm

    Aken

    2430 posts

    I’ve seen a couple other topics involving Smarty pop up lately - just though I’d bump this as another option for those wishing to utilize Smarty in their CodeIgniter install.

  • #3 / May 23, 2012 8:00pm

    Abel A.

    72 posts

    how do you pass variables?

  • #4 / May 23, 2012 8:25pm

    Abel A.

    72 posts

    I get this error when smarty compiles a template:

    A PHP Error was encountered
    
    Severity: Warning
    
    Message: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead
    
    Filename: sysplugins/smarty_internal_templatecompilerbase.php
    
    Line Number: 148

    it’s a fresh installation of CI w/ only your smarty plugin

  • #5 / May 23, 2012 10:16pm

    weboap

    169 posts

    thats a message from your php.

    in your php.ini add this line

    date.timezone = PST

    or
    add to your config/config.php

    date_default_timezone_set(‘America/Los_Angeles’);

     

  • #6 / May 23, 2012 11:54pm

    Abel A.

    72 posts

    thats a message from your php.

    in your php.ini add this line

    date.timezone = PST

    or
    add to your config/config.php

    date_default_timezone_set(‘America/Los_Angeles’);

     

    perfect, thanks 😊

  • #7 / May 24, 2012 9:26pm

    Abel A.

    72 posts

    I think I found a bug: You can’t load a view outside the CI_Controller class. Example:

    class Core {
    
     public $CI;
     
     public function __construct()
     {
      $this->CI =& get_instance();
     }
     
     public function msg($msg)
     {
      $this->CI->load->helper('url');
      
      //if (strlen($msg->location) > 1) header("Refresh:3;url=".base_url().$msg->location);
      
      $assgin_data = array("msg"=>$msg);
      $this->CI->load->view('pos_msg',$assgin_data);
      exit;
     }
    }

    In theory when $this->core->msg($msg) is called within a controller, the view should be loaded from the msg function. Is this a bug? or am I using CI improperly?

  • #8 / May 25, 2012 6:55pm

    Aken

    2430 posts

    What is Core supposed to be, a library? You don’t typically want to do any view loading or things of that nature inside libraries. I also don’t know what’s wrong if you don’t post an error or something. exit() is also likely preventing the output class from displaying the view you just tried to load.

    My advice would be to not do things that way in the first place.

  • #9 / May 26, 2012 1:17am

    weboap

    169 posts

    @berkguy i think you will have to do some reading budy! start here http://codeigniter.com/wiki/Category:Help::Tutorials

  • #10 / Oct 25, 2012 12:12am

    Jagar

    135 posts

    Hi Aken,

    Thanks for creating this tutorial for Smarty. I had configured smarty to work with CI but since I have upgraded to the latest version that doesn’t work anymore. So your tutorial came to the rescue.

    I have used your code and it seem to be working almost, but now I get the following messages

    A PHP Error was encountered
    
        Severity: Notice
    
        Message: Undefined index: CI
    
        Filename: compiled/060e3d07d36782b6d7a593e1ab9b4335bd4afa5f.file.header2.tpl.php
    
        Line Number: 37
    
    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Trying to get property of non-object
    
    Filename: compiled/060e3d07d36782b6d7a593e1ab9b4335bd4afa5f.file.header2.tpl.php
    
    Line Number: 37

    Also I have the following on

    $config['log_threshold'] = 1

    Thanks

  • #11 / Oct 25, 2012 12:22am

    Jagar

    135 posts

    I just looked at my header2.tpl file and I saw the following

    <li><a >uri->segment(1) == ""} id="selected" {/if} 
    <a >uri->segment(1) == "about"} id="selected" {/if}

    I will have to find another way to get this to work

    Thanks

  • #12 / Oct 25, 2012 1:59am

    Aken

    2430 posts

    Jagar, perhaps you have a syntax / parse error in your template file. Check all your braces and such.

    Also, if you’re trying to use the CI super object in your template, I believe you need to use lowercase “ci”. PHP variables are case-sensitive.

  • #13 / Oct 25, 2012 9:22pm

    Makelaly

    2 posts

    This is my first time i visit here. I found so many entertaining stuff in your post, nice to see that. especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up

    the good work.

  • #14 / Nov 02, 2012 10:44pm

    Jagar

    135 posts

    While I have the site set to the the following…

    define('ENVIRONMENT', 'development');

    I am getting so many notices for any variables that has no value.

    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Undefined index: variable_name
    
    Filename: compiled/05c167972ba6cf610a299ccf7eb20dfc787e78c8.file…..php
    
    Line Number: 45

    I understand that I can set the environment to production, but I would like to get rid of any errors and notices rather than hiding them and was wondering if you have workaround these

    Thank you again


    Thank you

  • #15 / Nov 03, 2012 7:44am

    Aken

    2430 posts

    Those errors come from your code, not the template library. Chances are you are trying to use a variable in your template that you have not added to your view data array.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases