Hello, this is Jan Lehnardt and you're visiting my blog. Thanks for stopping by.
plok — It reads like a blog, but it sounds harder!
↑ Archives
I want to use Code Igniter for some applications and I want to use some bits of the Zend Framework inside my Code Igniter classes. There is a tutorial explaining how to set it up. But there is a problem.
Code Igniter separates code into framework code and application code. The tutorial explains how to set up the Zend Framework as part of the application code. I find that conceptually interesting. It might even be desired at times but I’d rather opt for setting it up as framework code.
The solution outlined in the tutorial uses the hooks feature of Code Igniter to set up PHP’s include_path
. This feature however is limited to application code.
Here is my take. Instead of hooks, I’m going to use a helper and the autoload mechanism of Code Igniter. A helper is usually a collection of functions that do little tasks. Like making an HTML link out of an URI. My zend_framework_helper
does not define any functions, it just adds a new folder to the include_path
. This folder can live anywhere you like. By old conventions I name the folder contrib
. You may choose anything else here. I also put the folder inside Code Igniter’s system
folder that I share with different applications that should all benefit from the Zend Framework.
Here is the folder structure, so you get the idea.
codeigniter/system
/cache
/codeigniter
/contrib
/Zend
/Acl
/Acl.php
/...
/database
/...
To get things going, follow these steps:
<?php ini_set("include_path", ini_get("include_path").":".BASEPATH."/contrib/"); ?>
application
folder and open application/config/autoload.php
for editing. Find the $autoload['helper]
line and add zend_framework
to the list of helpers.
$autoload['helper'] = array("zend_framework");
class MyController extends Controller
{
function index()
{
require_once "Zend/Http/Client.php";
...
}
}
Done.
Hi, This is awesome. I have been working on codeigniter and was not convinced with the implementation of zend in CI but this seems to be cool. I am gonna give it a try ASAP.
Good Day !!!
It’s really interesting :)
Thanx. But how to integrate with zend GData?
just the same way? Change the require_once() statement and you are good to go.
thank you very much.!
Hi all. I’ve tried the way you told, integrating Zend framework with CI, but it didnt work. The error said that it failed to open the zend framework php class.
any clue?
What is the exact error message? Can you verify that your include_path gets set correctly?
Hi, I’ve tried integrated Zend framework with CI and unfortunately I’ve got an 404 error message. I’m blocked and stresed to find out a way to learn faster Zend framework. I’m a CI programmer. Can you help me to put them to work together? thank you
Hi Mina,
we’d need a bit more info about what you tried and what failed :)
Cheers,
Jan
I’m not sure if this is important of the case, but for me to get this working on a Windows/Apache server, I had to change ":" to ";" in the zendframeworkhelper. It may be the difference between a Linux server and Windows, I’m not sure, but it works when I do that.
Hi Brian, you’re exactly right. Windows uses ; to separate paths. To make this cross platform compatible, use:
PATH_SEPARATOR
instead of':'
.I encountered another strange behaviour:
If i insert the iniset line in the config.php everthing’s fine. But if i insert it into any other php-file (i.e. the helper, or a plugin zendfwpi.php-file), the ini_set won’t work.
Has anyone had the same error?