Welcome Guest, Not a member yet? Register   Sign In
Integrate Smarty Template Parsing into CodeIgniter
#1

[eluser]Aken[/eluser]
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

[eluser]Aken[/eluser]
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

[eluser]Abel A.[/eluser]
how do you pass variables?
#4

[eluser]Abel A.[/eluser]
I get this error when smarty compiles a template:
Code:
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

[eluser]weboap[/eluser]
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

[eluser]Abel A.[/eluser]
[quote author="weboap" date="1337825814"]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');



[/quote]

perfect, thanks Smile
#7

[eluser]Abel A.[/eluser]
I think I found a bug: You can't load a view outside the CI_Controller class. Example:

Code:
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

[eluser]Aken[/eluser]
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

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

[eluser]Jagar[/eluser]
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

Code:
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
Code:
$config['log_threshold'] = 1

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB