Smarty integration into the CodeIgniter framework - codeigniter

A Little Background Information:
I've been looking at a few PHP framework recently, and it came down to two. The Zend Framework or CodeIgniter.
I prefer CodeIgniter, because of its simple design. It's very bare bone, and it is just kept simple. The thing I don't like though is the weak template system. The template system is important for me, because I will be working with another designer. Being able to give him a good template system is a big plus.
Zend was the second choice, because of the better template system that is built in. Zend is a different beast though compared to CodeIgniter. It emphasis "loose coupling between modules", but is a bigger framework. I don't like to feel like I have many things running under the hood that I never use. That is unnecessary overhead in my opinion, so I thought about putting a template system into CodeIgniter: Smarty.
Question(s): How easy/hard is the process to integrate Smarty into CodeIgniter? From my initial scan of the CodeIgniter documentation, I can see that the layout of the framework is easy enough to understand, and I anticipate no problems. I want to know if anyone has used it before, and therefore are aware of any "gotchas" you my have experienced that is going to make this harder than it should be or impossible to pull off. I also want to know if this is a good thing to do at all. Is the template system in CodeIgniter enough for normal use? Are there any other template modules that are good for CodeIgniter aside from Smarty? I better off with Zend Framework? Is any wheel being invented here?

Sorry to resurrect an old question - but none of the answers have been flagged as "accepted" yet.
There's a library called "template" that does a great job of allowing you to use just about any template parser you want:
Template CI Library - V1.4.1
The syntax is pretty easy for integrating into your CI application and the smarty integration spot on.

Slightly OT, hope you don't mind...
I'm a Zend Framework user and I think it's worth saying that the loose coupling means you don't need to include any files you're not actively using. Hopefully this negates your concern about unnecessary overhead.
With the layouts stuff added in a recent release of ZF, its templating is really hard to fault... and it's completely pluggable as Favio mentions. The more I use ZF, the more I like it; they do things the way I would do them!

I did a quick google search and found the following:
http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html
http://codeigniter.com/forums/viewthread/67127/
If the designer is not familiar with Smarty, I think it's almost the same as if you use the existing CodeIgniter templating system (which leaves everything to PHP actually). It also depends on the complexity of the project at hand.
You can also hook Smarty with Zend Framework. It's more complex than with CodeIgniter, but there's already a primer on how to do exactly that in the ZF documentation. http://framework.zend.com/manual/en/zend.view.scripts.html Plus lots of tutorials on the net.
In my opinion it's almost the same, you can use pure PHP or Smarty as your template "engine", so it depends on the project. Also, compare a developer who has extensive experience and already has a library of view helpers so she uses pure PHP, versus a designer who doesn't know anything about PHP, but has extensive experience with Smarty. Sometimes decisions have to be based on who is going to do what.

Check out this custom CodeIgniter templating library. I've already used it on several projects and it is easy to use. I know this post is late but it's worth checking out.

It doesn't appear there has been an answer selected for this question nor has an up-to-date solution been given to work with the latest version of Codeigniter (2.0) and the latest version of Smarty (3.0.5).
This library allows you to use Smarty 3 with Codeigniter 2.0 so you can use Smarty 3 specific features like template inheritance.
http://ilikekillnerds.com/2010/11/using-smarty-3-in-codeigniter-2-a-really-tiny-ci-library/

Integrating Smarty in CodeIgniter? It is a breeze!
The template system in CodeIgniter is very basic.
Follow these steps for Smarty 3 in CI 3:
Download CodeIgniter 3
Download Smarty 3 and put its content in 'application/third_party/smarty' folder
Create 'Custom_smarty.php' file in 'application/libraries' and add this code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH.'third_party/smarty/Smarty.class.php');
class Custom_smarty extends Smarty {
function __construct()
{
parent::__construct();
$this->setTemplateDir(APPPATH.'views/templates/');
$this->setCompileDir(APPPATH.'views/templates_c/');
}
}
?>
Create 'templates' & 'templates_c' folders inside 'application/views' folder
Create simple 'test.tpl' file in 'application/views/templates' folder
Open 'autoload.php' in 'application/config' folder and add:
$autoload['libraries'] = array('custom_smarty');
And inside a controller: $this->custom_smarty->display('test.tpl');
If you are working on localhost set the permissions: sudo chmod -R 777 templates_c. Otherwhise contact your hosting service, if you catch the error Unable to write file. First be sure templates_c folder exists.
Otherwise you can use another template engine like Twig.

Related

How to use multiple themes in codeigniter like wordpress

I want to use multiple themes in codeigniter like wordpress.
e.g
Themes are A, B, C.
if i select Theme A then html would be change Theme A wise.
if i select Theme B then html would be change Theme B wise.
etc.
please help and thanks in advance.
Hi
Very hard to give this answer because your question is very out of range. :)
But I will try my best to do this.
Many way to build different themes put in CI
1) Use of CMS in codeigniter like
->http://www.getfuelcms.com/
->http://www.nodcms.com/en
2) Second way to do this things the easy way is to build your dynamic system as per your recruitment.
Also easiest way is to build your site in wordpress.
Although the library has it years(newer php version may scream error about &=, just delete & ) you can use https://github.com/philsturgeon/codeigniter-template - it uses theme concept. But you have to build database layer for themes usage logic. And if you know, which theme your site is using, then you just use method of the library: $this->template->set_theme($my_current_theme)
If you like a complete tutorial, check out this link
http://www.roytuts.com/using-template-in-codeigniter-3/. This is just an example, however and there's many more out there.
I agree with cssBlaster21895, that library can still be made to work for modern PHP versions. I just adjusted a few things and that made the errors disappear.

Differences Between PyroCMS and CodeIgniter

I am trying to learn how to make a site with PyroCMS. I know it is similar to CodeIgniter, but I have not worked on either in the past. I was wondering if anyone could tell me the differences, as most sites talking about PyroCMS will inevitably mention CodeIgniter as an explanation for anything potentially confusing about PyroCMS, but as they are tutorials about Pyro, they will not explain how to program in CodeIgniter. What is frustrating about this is they will not go into many core differences between the two, either, so it's not as easy as looking up a CodeIgniter tutorial and changing a few things.
I was wondering if anyone could tell me the main differences to watch out for that would be relevant for these tutorials. For example, the folder structure seems to be similar, but CodeIgniter has an Applications folder, while Pyro probably has another folder that does the same thing, but the Pyro tutorials don't say what that similar folder is.
PyroCMS is a CMS build on CodeIgniter. PyroCMS is used by individuals, small & medium-sized businesses, and large organizations worldwide to easily create & build a variety of websites & web-enabled applications.
CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.
UPDATE:
One good overview for PyroCMS you can read here
PyroCMS is built using modular MVC, which means (in short) that each part of the system is its own micro-instance of MVC. This allows the system to be more flexible and cleanly organized than other CMS platforms. PyroCMS describes itself as a simple, flexible, community driven content management system.” And because PyroCMS is powered by CodeIgniter (at least for a bit longer, while the team migrates over to a Laravel backend), it is easy to learn, understand, and own.
CodeIgniter (CI) is one of popular php framework,it is very help full whenever we need to build large websites using php.It has so many libraries,helpers and plugins.But, CodeIgniter is not everything. We will not find 'engine generator' that can build page self. Several frameworks have features like that. For example, they can create web page (that to do basic Create, Read, Update, and Delete operation) automatically. CodeIgniter doesn't do this.
But codeigniter is very useful to decrease our code maximally without loosing functionalists.

Content Management System - PHP - Asp.Net

I am new to open source Content Management System tools. I got a website using Joomla for content management. Now, I am just thinking to Umbraco or Dotnetnuke (any Asp.net based) frameworks to use. Will it be a complex to do this migration. Can you suggest pros and cons for this idea.
Any help is appreciated. Thanks !
For Umbraco ...
Most of your client-side code like HTML, CSS and JavaScript can just be copied straight over, but as expected it may require some fiddling.
As for the data, it might be worth looking into the CMSImport module for Umbraco. As long as you can convert the source data into one of the formats recognised by the module, you should be able to upload your content with ease. I've had no personal experience with this module, but should be worth a shot.
It really depends on the size of the site and the functionality requirements. For smaller sites, it may be as easy as implementing the skin based on the original design (or, if a custom design isn't needed, selecting a free or 3rd party skin) and then manually migrating the content. For really large sites, you should be able to write scripts to migrate the content. I'm not aware of any products that do this. You'll also probably need to select some modules to use for things like forms.

CodeIgniter 2.1.0 Template Library

Recently CI 2.1.0 is out.
I have a question. As I recognized that the CI folder structure has been 'evolved' (easy to setup, automatically defines base_url,etc), I'm wondering if the current template libraries like Phil's,william's concept,ocular,etc.. can be adapted to this new CI version.
I've tried Phil's but no luck, I mean..I don't know if I'm missing something this time, and ocular, also, to no avail ( I don't subclass the Controller, as suggested here)
Any better templating suggestions that will be suited enough to the latest CodeIgniter 2.1.0?
Thanks.
It seems like from the comments above that you're having trouble finding any resources online on the matter. Here's my suggestion for you:
Check the CodeIgniter Change Log here, and compare all the changes between this newest release, and the release that you know last worked with the template libraries that you've mentioned above. Use deductive reasoning, and see if you can find a way to modify the templates you need to work with the current CodeIgniter structure. I know that's a lot of work, and is not ideal for your situation. Regardless, it's the best advice I can give at the current moment. Good luck, and happy reading!

codeigniter scalable folder structure

I've use symfony and now using codeigniter is there any folder structure
that can be used in scalable applications similar to symfony.
I want to make an application that will be divided in sub-apps and the sub-apps
will have their own modules.
Thanks.
What you are describing is called HMVC (Hierarchical Model View Controller). This means that an application is split up into modules (or as you described them, rather accurately, "sub-apps"). Sadly CodeIgniter does not support HMVC unmodified, however there is a drop-in extension for CodeIgniter which allows you to use a HMVC architecture. [Thanks Wesley]
Alternatively you can use a fork of CodeIgniter which is specifically designed for HMVC called Kohana Framework. The project was originally a fork but has now changed massively and is barely recognisable from the original CI project.
As far as modules go, the go-to solution for CI is the HMVC package:
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
This is a "drop-in" solution; very easy to install, has been around for quite a long time, and is actively maintained.
Since Codeigniter tries to stay lightweight, you'll find that a lot of important things you need, like Auth or ORMs, are not built in, and you have to use third party code.
A lot of solutions hosted here: http://getsparks.org/packages/browse/latest
And the wiki: http://codeigniter.com/wiki/

Resources