Thứ Năm, 24 tháng 4, 2014

External modules [Media Sharing]

One of the most importanfeatures of Zend Framework 2.0 is the ability to integratexternal modules in your PHP application, and this integration is completely managed using a dependency managementool (in ourcase, Composer).

This feature allows development of PHP applications without having tworry about maintaining external libraries inside your application. Libraries and applications can be decoupled and maintained separately.


In this chapterwe will be using an external module for resizing images; we will also make use of external libraries for connecting to Google services.

Resizing images


Zend Framework 1.0 had a resize filter that allowed images to be resized on upload; with Zend Framework 2.0, this option no longer exists. Our nextask will be to find a simple image-resizing module and install it in our application. So let's gestarted.
Carry out the following steps:

1.       Go to the Zend Framework 2 module's site:

2.       Run a search for WebinoImageThumb.
3.       To install this module, you will need to updatcomposer.json in the application root and include this module as a required module.
4.       To do this, edit CommunicationApp/composer.json and modify the required section:
"require": {
"php": ">=5.3.3", "zendframework/zendframework": "2.0.*", "webino/webino-image-thumb": "1.*",
}

5.       Now run composer.phar update to install the newly added dependency.
$ php composer.phar update
Loading composer repositories with package information Updating dependencies
- Installing webino/webino-image-thumb (1.0.0)


Downloading: 100%


Writing lock file Generating autoload files
6.       You will be able to see the newly installed modules in the vendor folder as follows:



7.       Now that the module is downloaded, we will need to activate the module in CommunicationApp/config/application.config.php by adding 'WebinoImageThumb' to the modules array.

return array(
'modules' => array( 'Application',
'WebinoImageThumb', 'Users',
),


What just happened?
We have installed an external module into our application using the dependency managementool, ComposerWe have also activated the module in our application so that the module is accessible across the application.

Không có nhận xét nào:

Đăng nhận xét