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.
Related
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
Originally, I was searching how to use php to retrieve book information from amazon. and I found this question:
How can I use Amazon's API in PHP to search for books?
I think this works, but I am having stupid question. I am not able to install and use Zend Service Amazon. I downloaded the software of around 60 MB but, was corrupted.
May be, I actually want some php files to implement it. but, its giving some kind of exe file.
so, here my question is;
Where do I download Zend framework?
How do I install it?
How do I use it?
Thanks in advance
The official download for Zend Framework can be found here. Since you intend to use ZF more as a library than an MVC application framework, you only really need to download the much smaller minimal package.
From looking at the Amazon files you are interested in, I think the list of the following files are all you would need to copy into your application in order to use the Zend Framework Amazon Service APIs (when I use ZF as a library, I always try to only include the actual files I will be using, rather than the whole package, but for starters you can just copy the entire Zend folder to get going):
Zend/Exception.php
Zend/Loader.php
Zend/Loader/Autoloader.php
Zend/Loader/Exception.php
Zend/Uri.php
Zend/Uri/Exception.php
Zend/Service/Abstract.php
Zend/Service/Amazon.php
Zend/Service/Exception.php
Zend/Service/Amazon/Abstract.php
Zend/Service/Amazon/Accessories.php
Zend/Service/Amazon/Authentication.php
Zend/Service/Amazon/CustomerReview.php
Zend/Service/Amazon/EditorialReview.php
Zend/Service/Amazon/Image.php
Zend/Service/Amazon/Item.php
Zend/Service/Amazon/ListmaniaList.php
Zend/Service/Amazon/Offer.php
Zend/Service/Amazon/OfferSet.php
Zend/Service/Amazon/Query.php
Zend/Service/Amazon/ResultSet.php
Zend/Service/Amazon/SimilarProduct.php
Zend/Rest/Client.php
Zend/Rest/Client/Result.php
Zend/Rest/Client/Result/Exception.php
Zend/Crypt.php
Zend/Crypt/Exception.php
Zend/Crypt/Hmac.php
Zend/Crypt/Hmac/Exception.php
If I missed any, forgive me; you should get an exception saying class not found if I left any out, and that should be pretty straightforward to resolve which additional file(s) you need to include.
In order to use Zend Framework I recommending doing the following:
First and foremost, add Zend Framework's files to your PHP include_path. In order to use the ZF files, you need to preserve the directory structure they use, at the very least, you need a Zend folder with all the ZF files in there.
Add to your include path like this:
set_include_path(get_include_path() . PATH_SEPARATOR . '/zf/folder/path');
zf/folder/path should be the path to the folder that the Zend directory is in, but make sure not to actually include the Zend folder in the include path (since Zend does require_once 'Zend/File.php';
Secondly, set up the autoloader if possible. If you decide to use the Zend Framework autoloader, you won't have to manually 'require_once' many of the ZF files.
To set up their autoloader, all you have to do is get an instance of it:
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
You don't need to save or do anything with $autoloader. Just that call is enough to register the Zend autoloader. Since the ZF files are in your path, it will automatically know how to load and locate all ZF files.
After you perform those steps, you are able to use the Amazon services via Zend Framework in your PHP application.
As for the details of using that, hopefully you can find all the details and help you need here, Zend_Service_Amazon Reference Guide. The reference guide should be your best bet, but you can always find the phpDocumentor class documentation here.
Hope that helps! Feel free to ask if you need clarification on anything.
Why do I have to configure an include_path when installing Zend Framework instead of just manually including? I've never done this before and can't really see the point, also I've spent some time trying to figure this out with no luck hence why I ask.
Actually I add Zend framework to the include path to be able to use Zend tool.
If you want to create a project structure and add controllers or models or even scripts using Zend Tool you will have to have Zend framework added to your include path.
Another reason you may want to ship your project without the library itself so that the end user doesn't update the framework version himself and break your code.
Also if you are working on different project at a time you may want to keep only one version of the framework shared between different projects. This is handy when you need to update your version of the framework without going through all projects every time.
You don't have to set your php include_path to include the ZF library you could just copy the whole ZEND directory into your applications Library directory and continue on.
But a lot of us are working on more then one project or don't want to have the library in our application so we add it to the php include_path so php and our application can find it.
Now if you are refering to the windows or linux path, those are required to use the ZF cli components ZF.bat and ZF.sh
When modifying the Include Path you can use Zend Framework without knowing the Full-Path of it. You can simply use require('Zend/Loader/Autoloader.php') and PHP will search in every include path.
For more information have a look at: http://php.net/manual/en/ini.core.php#ini.include-path
I am currently integrating the Zend Framework in my current project named VMM.
I decided to put the Zend Framework directory as a standalone project next to my VMM project in Eclipse.
I need to do some customization of the zend framework (For example I need to add Irradiance.php into Measure) and I would like to know where is the best place to put all my customizations.
I know that I need to follow the Zend Framework naming convention and the same directory structure.
So for example Irradiance.php contain the Mylib_Measure_Irradiance class.
I was thinking to put the Mylib folder into ZendFramework/library/Mylib next to the Zend folder.
Is it the regular way to extend and customize the Zend Framework?
If not, should I put the customizations inside my VMM project or as an other standalone project?
Thanks!
UPDATE
This question helped me but I still need some help...
I tend not to put my own library style files into the ZF folder mainly because when you come to upgrade ZF you'll have to copy them all over to the new ZF.
On my localhost I have something like this
my-project is the project I am working on and contains all the models, views, controllers,etc for that project
/htdocs/my-project/application
/htdocs/my-project/public
library is my own library files and mimics the ZF structure
/htdocs/library/Db/
/htdocs/library/Validate/
I then have my current ZF in /usr/lib/php/ZendFramework-x.xx.x this folder contains the latest ZF and can be changed easily without changing my projects or library code base.
Edit:
David's comments about 'pointers' reminded me, I always set up a sym link in /usr/lib/php/ called ZendLatest, this points to the latest copy of ZF, this means I don't have to keep changing my code or my php.ini.
There are many ressources out there:
http://www.slideshare.net/PHPBelgium/extending-zend-framework-presentation
http://cslai.coolsilon.com/2009/03/28/extending-zend-framework/
I'm going to use Zend framework but just some tool of Zend like translate, date and cache. Can I use it as standalone class? My project has it own structure and I don't want use the whole Zend fw. If yes, which files should I include in my project? Is there a docs for using each Zend fw tool as standalone?
And remember, to use various Zend Framework components in another project, you just need to have the Zend library somewhere on your include_path. Copying the whole thing may seem overkill to use one component, but it's only disk space. Having those files there doesn't affect performance unless they are called upon. And this way, you don't have to sweat the dependencies, like Zend_Exception and its various component-specific subclasses.
So, for example, if you have a folder myapp/lib to contain your external libraries, you simply make sure that your include path contains that lib folder and copy the Zend folder into it as myapp/lib/Zend.
Then to use a component like Zend_Translate, all you have to do is something like the following:
require_once 'Zend/Translate.php';
$options = array(
// your options here
);
$translate = new Zend_Translate($options);
With some kind of autloading mechanism in place, you can avoid even the require_once call. Setting up autoloading is as easy as putting the following in some kind of common/bootstrap file:
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
Then any classes that follow the PEAR 1-class-1-file naming convention can be loaded without explicitly adding any require/include statements.
If disk-space really is a concern and you really don't want the whole Zend library, then you could investigate a packageizer, like Jani Hartikainen's Packageizer.
As an answer i could say Yes of course.
for example if u want to use Zend_Translate copy Translate.php and Translate folder to your library directory.
some times inside a class some other classes have been used. u have to copy them too. i find them by reading raised errors. ;)