Why Zend Framework has to be configured through include_path - php

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

Related

Eclipse: Share a large framework with multiple projects?

We develop in PHP and HTML/Javascript.
Over time we developed a very big source code library, that contains a couple of hundred PHP and Javascript libraries, that we use for every project. The framework resides its own svn-repository, that we include with an external svn link in each project.
The problem is, that the entire framework itself is about 800MB now.
With only a few projects that we worked on, this wasn't really a problem, but now we have about 30 projects, that all contain a FULL copy of the framework, which takes up a lot of space, and requires constant updating of each copy.
Somehow I would like to have the framework outside the project folders. I've read about referencing other projects in Eclipse, but couldn't really get it to work.
How do you setup the include paths so that each projet 'thinks' that the framework is normally inside the project folder? And can you make a virtual link in an Eclipse project to edit files in the framework just as you would normally do, and get code assist for the libraries too?
One of the main problems is that all our code (and some libraries in the framework itself too) relies on the fact that the framework is in a folder 'framework' inside each project. I'd rather not change all those references to a different path, so maybe I need some .htaccess trick to make this work...
Does anybody else follow the same procedure?
Any advice ?
can you use the "big" project as target platform?
why-create-a-custom-target-platform
If you define it as target platform, the sources are available in your workspace, but they are placed in 1 folder for multiple workspaces. the workspaces will link to the platform, but will not check them out.

Using Zend Service Amazon

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.

Zend Framework and the location of the zend library

I am currently working on several zend projects, and the approach I took initially was to dump the Zend framework into Wamp Servers root directory (wamp/www).
I then used the zf tool to CREATE PROJECT (multiple times) into a folder called Projects_Zend which is also in Wamp's root.
I then copied and pasted the entire Zend framework into each of my projects library folder, where I set the appropriate paths for each project.
QUESTION:
Is this a good approach, as I now have multiple duplicate copies of the zend framework, one for each of my projects.
QUESTION TWO:
How to avoid this??
Any help/advice welcome....
Well, if all the websites will always be on the same server this is good reason to have only one copy of ZF. But keep in mind if one project uses something that gets broken/removed/whatever in a future upgrade you could find it difficult to manage.
This question is very situation dependent. Both solutions can be right.
Personaly I always have a copy of zf in a projects folder since it's not like its a ton of space lost and my projects tend to be on seperate servers.
Hope this helps!
About question 2: you don't have to avoid anything. Just do whatever is right for your context. If you want a more precise answer I guess you should give us more information about the relation between all these projects/websites.
About "Does the location of the zend library even matter? ": well as long as its out of the public directory to avoid peoples invoking script files no it does not mater much.
you can either put zend library on the php include_path or in your case using symlinks maybe better.
but there's no harm in putting it in a library folder inside of each project.

configure zend framework library path

i want to know where can i put the "library" folder in my zend project. Presently i have it in the location of my Zend server. This is my current "library" path:
E:\zend\ZendServer\share\ZendFramework\library
And here is the path to my "app" project:
E:\zend\Apache2\htdocs\app
Inside the "app" project, i have the folders like "public" and "application".
Now how can i integrate the "library" into my "app" project, without referencing it from zendserver?
The easiest way it is to put those library files to the library dir (as in the other answers), but you should consider keeping them separated from the application.
It's easier to have separate git or svn repos for the libraries. Easy to update and maintain for multiple projects at once. Putting them in library will also won't work if you installed the libraries from the bundle, e.g. apt-get install zend-framework-library.
To have the libraries in any directory you want, just add it to the include_path array in the index.php.
Quite often, you'll see a folder called like "lib" or "libraries" in your application (next to public, application, ...).
In that folder, you'll put the frameworks you're using.
For example :
public
application
libs
Zend
Doctrine
...
To get Zend Framework, just download it, and unpack it to the right folder ;-)
Advantage : you'll be using the version of your choice -- and not the one, possibly outdated, provided by your environment.
And, as a reference, you might want to read the Installing The Zend Framework chapter of the e-book Survive the Deep end.
In your app project u should have a library folder and should contain zend folder in that..so just copy library folder and put it in E:\zend\apache2\htdocs\app.
Please don't tell people to deploy 3rd party libraries to their application project folder, it is bad practice. Deploy your libraries to a path that you have access to, which is outside of your project, and reference it in your include path.
During development, it is fine to have the library in your project, for reference sake, but exclude it in your deploy script and instead have your deploy script either set an environment variable, or have it update your include path.

How should I extend the Zend Framework as a folder organisation point of view?

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/

Categories