EllisLab text mark
Advanced Search
1 of 2
1
   
Integrate Smarty Template Parsing into CodeIgniter
Posted: 30 January 2012 10:14 PM   [ Ignore ]
Avatar
Joined: 2007-11-28
2435 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!

 
Posted: 19 February 2012 04:41 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 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.

 
Posted: 23 May 2012 08:00 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-04-18
79 posts

how do you pass variables?

 
Posted: 23 May 2012 08:25 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2012-04-18
79 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

 
Posted: 23 May 2012 10:16 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-05
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’);

 

 
Posted: 23 May 2012 11:54 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2012-04-18
79 posts
weboap - 23 May 2012 10:16 PM

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 smile

 
Posted: 24 May 2012 09:26 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-04-18
79 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?

 
Posted: 25 May 2012 06:55 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 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.

 
Posted: 26 May 2012 01:17 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-05
169 posts

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

 
Posted: 25 October 2012 12:12 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-22
154 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 indexCI

    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'

Thanks

 
Posted: 25 October 2012 12:22 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-22
154 posts

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

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

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

Thanks

 
Posted: 25 October 2012 01:59 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 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.

 
Posted: 25 October 2012 09:22 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2012-10-24
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.

 
Posted: 02 November 2012 10:44 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-22
154 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 indexvariable_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

 
Posted: 03 November 2012 07:44 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 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.

 
Posted: 03 November 2012 11:05 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-22
154 posts

Thanks again Aken, I have defined the variables and the errors are not coming back

Regards

 
1 of 2
1