How to combine zend framework and Codeigniter ?
I have two applications, one is zend and other one is codeigniter, is it possible to combine the two framework in to one project ? If so, How to combine the two framework and what are the files structure for this ?
Thank you for you help.
Ofcourse it is possible.
I have worked on one project where we had Zend + CodeIgniter both.
Here is what you need to do:
1. Copy paste your Zend folder (library) into Library of CodeIgniter OR viceversa copy CodeIgniter library into zend library folder.
2. If in codeigniter, call it using $this->load->library('Zend', '{anything here}')
or in Zend use autoloader
Issues you WILL face (which I faced):
Authentication
Zend uses Zend Auth Namespace which uses $_SESSION . Whereas CI does not use $_SESSION but, has it's own built in system. Use Zend and (assuming your entire app is on same domain only) see what it stores for identity, check for that $_SESSION directly via CI and assign CI cookies. Here is what happened with me and check the solution.
Security and Forms
Both CI and Zend have different libraries for Forms, do not use Form of CI in the class which loads Zend Library (under CI), just remember this as a thumb-rule. So, you need to strategize how you will implement it, Zend on CI or CI on Zend. Do not use validators of Zend in CI forms (I know no one will do it but, once I did, so anyone can do it! DONT DO IT). Use same library of security which library you will use for forms
Personally, my project did great (ofc after lot of research), it was : CI on Zend, where I HAD to use Zend Auth.
Questions? :)
As far as combining frameworks go its typically best to stick with one framework's ideology. Otherwise, why use that framework? Save for specific pieces of functionality.
As far as CI and Zend Framework go, Zend was actually built to be more modular (its essentially a collection of libraries anyway) and would be significantly easier to incorporate into CI than the other way around.
This is a common "problem" amongst those using PHP frameworks that many have solved already.
A quick google turned up the following:
http://viraksun.com/tutorials/integrate-zend-library-in-code-igniter/
http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/
http://www.gotphp.com/codeigniter-with-zend-framework-libraries/54312/
To answer your question more directly:
You could simply place the "Zend" folder (from Zend_Download_Folder/library)
in the main "libraries" folder, or within your personal application/libraries folder.
Then, from within any Controller use the loader class to load whichever Zend class you want to use.
For Example, to use Zend_Pdf, do the following in your controller:
//load it
$this->load->library('Zend/Pdf');
//use it
$zendPdf = new Zend_Pdf();
$zendPdf->someMethod();
Source:
http://codeigniter.com/user_guide/general/creating_libraries.html
http://codeigniter.com/user_guide/libraries/loader.html
Related
I have an project that is used by many users and it's written in Codeigniter. I'm very happy with my application but I'm getting lost with Codeigniter because of the functionality of the framework and my application is getting too big for Codeigniter (that is what I think).
I want to go from Codeigniter to Zend, but the application is too big to begin all over again because there is still more functionality to come.
I don't know if someone has experienced or tried it, but does anybody know if it is possible to integrate Codeigniter into Zend as an module and migrate in steps to the Zend Framework 2?
Sorry for my bad english by the way :-)
Having experience with small and medium-scale projects with both CodeIgniter (CI) and Zend Framework (ZF), I can tell you that using one framework over the other will not solve any problem you might be having.
If you are looking for the added functionality provided by the ZF components, such as a ready-made class for Date or the Form verification class, know that you can use ZF components in Code Igniter. You will need to create a special class in CI that will jumpstart the ZF class autoloader. From there you can simply include ZF classes and use them as if you were inside a ZF application.
See http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/ and http://fr.slideshare.net/samsonasik/codeigniter-using-third-party-components-zend-framework-components for more details.
"Integrate" means you want to put your app running on CodeIgniter withing ZendFramework. So basically you changed nothing and there's no much sense of doing so.
You perhaps could consider porting your app from CI to ZF, but that will require rewriting of your code. But I'd first try to find out what the bottleneck in your app really is and ensure that you will benefit from the switch
Zend framework is well known for loosely coupled components.
I would like to use XML-RPC from zend framework, is there any dependency for XML-RPC? Like if I had taken out XML-RPC folder off Zend Framework Library and try to instantiate RPC object, would it throw error?
Where can I find the proper way of separating component from the framework?
Thanks
I wrote a tool which takes ZF components and their dependencies so you can easily take just one (or several) component from ZF.
http://epic.codeutopia.net/pack/
It doesn't have the latest ZF release 1.11 (because I'm lazy), but 1.10.6 should work just fine.
You should never split single components off a framework or library independent from Zend Framework, or any other. Especially when using PHP there is also no performance reason, because with PHPs autoloading functionality it will always just include the files, which are requested.
You should literally be able to copy the XmlRpc folder from your copy of Zend Framework and use it in your own projects. The only dependency that I can see is in XmlRpc/Exception.php as it requires a file in the root directory of Zend/ (Exception.php) you could simply copy this file along with the XmlRpc folder keeping the directory structure the same and it should work....
My first question is why you would want to do that in the first place. It means that every time you upgrade Zend Framework you now need add a bunch of tooling to manage the removal of some components. One of the purposes of using a framework is so you don't have to manage a bunch of code. Removing parts of a framework is a step backwards IMHO. Disk space is cheap. Network transfer is cheap. If you are going to remove parts of a framework you should have a REALLY, REALLY good reason to do it.
There seems to have been previous attempts to integrate Zend with Symfony in the same project. I hear it can be done and has been done, but aside from a slide show linked below, the actual video accompanying the slide show is not freely available.
So does anyone know of good resources that explain such integration well? blogs, videos, whatever. I'll add whatever you post here for easier access to others in the future.
Resources I've found so far:
this text slide show
Edit: I should add if you've done this
yourself before, can you also please
post any tips (as little or lots) to
help those who may want to try it.
It is completely simple to add the Zend framework to run in Symfony. There are certain components of the Zend framework that compliment the Symfony framework. I am currently using Zend for the Lucene Search, as well as their Mailer.
To use Zend in Symfony, you just need to do two things:
Copy the Zend framework to your /lib/vendor/ folder.
Modify the ProjectConfiguration file. (config/ProjectConfiguration.class.php)
class ProjectConfiguration extends sfProjectConfiguration
{
static protected $zendLoaded = false;
static public function registerZend()
{
if (self::$zendLoaded) { return; }
set_include_path(sfConfig::get('sf_lib_dir').'/vendor'.PATH_SEPARATOR.get_include_path());
require_once sfConfig::get('sf_lib_dir').'/vendor/Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
self::$zendLoaded = true;
}
}
All this can be found in the Symfony tutorial here:
http://www.symfony-project.org/jobeet/1_4/Doctrine/en/17
From the discussion above:
I was thinking to use Symfony as the base + Zend components as needed. So I will be using Symfony's folder structure but none of Zend's bootstrap and ini.
From my experience with ZF I would say, this can definitely be done and is worth simply getting started with.
You'll have to haggle with Autoloading a bit (you should probably load all Zend related includes manually and not use its autoloader at all) but other than that, I can't see any problems. (disclaimer: I don't know Symfony in depth at all and can't comment on possible namespace collisions, but seeing as Zend was built to avoid those, and Symfony is a mature framework, I don't think you'll encounter anything impossible.)
If you're using Symfony as your top-level framework, it's trivial.
In fact, integrating a Zend Framework component even used to be part of the standard symfony tutorial.
I'm working on a project now that isn't based on Zend Framework, however I would like to use some of Zend's components in it, namely Zend_Form and Zend_Acl.
The question is, what should I do in order to make these components know how to load their classes correctly when they are instantiated.
I suppose spl_register_autoload and set_include_path should be used, just can't figure out how exactly.
Thanks guys,
Zend_Loader_Autoloader::getInstance() plus setting right initial path in set_include_path did the trick.
If it's just two Zend Framework components you want to use, you could include them manually.
What I usually do when I need a few Zend Framework components is to load the via autoloader.
You can find several questions and answers on how to use the Zend Framework autoloader on SO, for example this.
If you do not want to use Zend_Load_Autoloader::getInstance() to let Zend register its autoloader with spl_register_autoload() you just need to put the folder which contains Zend folder on your.
For example if your Zend components are located in "library/Zend" you have to put "libray" on the path, not Zend. Then you can include files like "Zend/Validate/Interface.php" since they are on your path.
If I understood you correctly, you want to use one copy of Zend Framework in multiple projects. For that purpose, simply edit includePaths.library in your application/configs/application.ini file.
I was wondering if anyone knew how to use some components of the Zend Framework without having to actually use the framework. For example, I would like to use their Zend_Validate components, but don't want the overhead of the framework as it's a small one-page script.
Can this be easily done, and if so, are there guides/tutorials on how to accomplish it?
Zend framework components are intentionally designed to be loosely couple from the framework itself.
The component structure of Zend
Framework is somewhat unique; each
component is designed with few
dependencies on other components. This
loosely coupled architecture allows
developers to use components
individually. We often call this a
"use-at-will" design. [from here]
Here's a tool for pulling out specific components and their dependencies to use in your application.
I've just grabbed the whole Zend package, and used pieces of it. It always seems I end up using more of it as time goes on, so I keep it up to date even if I'm not using some of the MVC stuff in one project or another. Holding on to the whole thing makes you not have to worry about the dependencies (and how they might change down the road).
Zend framework components while being loosely couple are still coupled. If you would to use Zend_Mail component for example - that would actually also require:
Zend_Mime
Zend_Exception
Zend_Validation
Zend_Validation will be loaded for the mere reason of validating email address domain.
So - best bet would be to include entire Zend library. By pulling only several components - you'll soon end up in "dependency hell" especially as API changes (though that doesn't happen too often).
Also - starting from version 2.0 you must use some auto-loader to load Zend components as all require calls will be removed from PHP classes.