Search code examples
phpamazon-web-serviceszend-framework

How can I download, install, and use the 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?


Solution

  • 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.