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.
Related
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 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.
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. ;)
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.
What is the best way to integrate an external script into the Zend Framework? Let me explain because I may be asking this the wrong way. I have a script that downloads and parses an XML file. This script, which runs as a daily cron job, needs to dump its data into the database.
I am using Zend Framework for the site which uses this script and it seems to me that it would be best to use my subclassed model of Zend_Db_Abstract to do the adding and updating of the database. How does one go about doing this? Does my script go in the library next to the Zend Components (i.e. library/Mine/Xmlparse.php) and thus have access to the various ZF components? Do I simply need to include the correct model files and the Zend DB component in the file itself? What is the best way to handle this sort of integration?
Yes, you should put your own classes that maybe inherit Zend Framework classes or add further classes into your own folder next to the Zend Framework folder in library.
When you have Zend_Loader s auto-loading enabled, the class names will automatically map to the class you created, e.g.:
My_Db_Abstract will map to My/Db/Abstract.php .
In your library directory you should have your own library next to the Zend library folder. Whatever you call it (Mylib, Project, ...) you should include it into the Zend Autoloader and that's done as follows:
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Project_');
$loader->setFallbackAutoloader(true);
if ($configSection == 'development')
{
$loader->suppressNotFoundWarnings(false);
}
In order for you library to integrate nicely with ZF and the Autoloader you should stick to the ZF naming conventions. This means two things:
if you extend an existing ZF class, replicate the ZF folder structure so that your file has the same path and name except for the library name. E.g. /library/Zend/Db/Abstract.php => /library/Project/Db/Abstract.php.
if you write your own classes, still stick to the ZF naming conventions for the autoloader to find them.
I just came across something that may be germane to this question. This IBM developerWorks article.
The author recommends simply creating a scripts folder in the ZF hierarchy and the using it as one normally would within ZF (though he does set the ini path and call autoload). Is it that simple? Does simply being in the hierarchy of the framework and including the path and autoloader grant your script access to all of the goodies?
I'm not 100% sure what you're trying to ask but I will try to help. If at any point you add a reference to "/path/to/zend/framework" into your php include path then you have in essence enabled the Zend Framework. From there if you do:
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
Then at any point in your script you can pretty much just create new Zend Framework objects and Zend_Loader will handle the rest.
One of the big things about the Zend Framework though is not forcing you to do things a certain way. That's why sometimes there are several ways to accomplish the same thing. So, if you feel you need to make your script use the Zend Framework just for the sake of doing so this is not really necessary. But if you think it may improve your script in some way then go for it.
I usually put custom stuff that I think could be used across projects in a custom folder in the library. So I have a library/Ak33m folder that has scripts that may be outside of the framework.
As a ZF noob myself, I think I understand some of what the OP is trying to figure out. So, I'll just explain a bit of what I understand in the hope that it is helpful either to the OP (or more likely, to a future reader, since the original question is so old and I imagine that OP is now a ZF guru).
I understand that ZF claims to be largely "use at will", so that you need no buy into an entire structure, like the Zend_Application, the Zend_Bootstrap class, the entire MVC approach, etc.
Further, I understand conventions for class naming and file locations that enable easy autoloading. Ex: class App_Model_User resides in a folder App/Model/User.php
I think what can be potentially confusing is that in the script context, where you have not yet
done the .htaccess magic that pushes all request to public/index.php
set your APPLICATION_PATH and include paths in public/index.php
created your Application or Bootstrap object tied to a config file
it can be a little bit unclear how best to avail yourself of most of the ZF goodness we get in that context and want in another context.
I guess my answer to the original question would be that the usual entry point sequence of
http request -> .htaccess -> index.php -> config
sets up much of our environment for us, we would need to duplicate some of that for different entry path.
So, for your script, my first instinct would be to create a common include file that mirrors much of what happens in index.php - set the include paths, the APPLICATION_PATH, instantiates and calls a bootstrap, and then does your script-specific processing.
Even better, it might be desirable to create a single entry point for all your scripts, like we do in the http/web context. Extend Zend_Application for your own script purposes so that $application->run(); no longer starts up the MVC router-controller-dispatch processing, but rather does your own stuff. In that way, this single script entry point would look almost identical to the web entry point, the only difference being which application object gets instantiated. Then pass the name of your desired Application class as a command line parameter to the script.
But here I confess to being less confident and just throwing out ideas.
Hope all this helps someone. It actually helped me to write it all down. Thanks and cheers!
Update 2009-09-29: Just ran across this article: Using Zend Framework from the Command Line
Update 2009-11-20: And another article: Cron jobs in Zend Framework | GS Design
Update 2010-02-25: Easy command line scripts with Zend Application - David Caunt