PHPackages                             uploadcare/uploadcare-zend2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. uploadcare/uploadcare-zend2

ActiveLibrary

uploadcare/uploadcare-zend2
===========================

Official Uploadcare package for Zend Framework 2

v1.0.1(12y ago)043PHPPHP &gt;=5.3.0

Since Aug 15Pushed 6y ago15 watchersCompare

[ Source](https://github.com/uploadcare/uploadcare-zend2)[ Packagist](https://packagist.org/packages/uploadcare/uploadcare-zend2)[ Docs](https://github.com/uploadcare/uploadcare-zend2)[ RSS](/packages/uploadcare-uploadcare-zend2/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Uploadcare Zend Framework 2 Module
==================================

[](#uploadcare-zend-framework-2-module)

This is a module for [Zend Framework 2](http://framework.zend.com/) to work with [Uploadcare](http://uploadcare.com/)

It's based on a [uploadcare-php](https://github.com/uploadcare/uploadcare-php) library.

Requirements
------------

[](#requirements)

- Zend 2.0+
- PHP 5.3+
- php-curl

Install
-------

[](#install)

### GitHub

[](#github)

Clone module from git to your vendor directory:

```
git clone git://github.com/uploadcare/uploadcare-zend2.git vendor/Uploadcare --recursive

```

### Composer

[](#composer)

Update your composer.json:

```
"require": {
  "uploadcare/uploadcare-zend2": "dev-master"
}

```

Install package:

```
composer update

```

Fetch submodules from github:

```
cd vendor/uploadcare/uploadcare-zend2/ && git submodule init && git submodule update

```

Edit your config/application.config.php and add new module. It should look like this:

```
return array(
    'modules' => array(
        'Application',
        'Uploadcare',
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            './module',
            './vendor',
        ),
    ),

```

);

Inside your config/autoload/global.php add:

```
return array(
    'uploadcare' => array(
      'public_key' => 'demopublickey',
      'secret_key' => 'demoprivatekey',
    ),
);

```

Usage
-----

[](#usage)

You can access uploadcare api service inside a controller like this:

```
$uploadcare = $this->getServiceLocator()->get('uploadcare');

```

It will return a UploadcareZend object. This class extends Uploadcare\\Api class.

Create a from to show Uploadcare widget. Use UploadcareInput class as a field.

Inside your controller:

```
namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Uploadcare\Form\UploadcareInput;
use Zend\Form\Form;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        $uploadcare = $this->getServiceLocator()->get('uploadcare');

        //file_id is name of input for widget.
        //You will recieve File ID at CDN from this field.
        $uploadcare_widget = new UploadcareInput('file_id');

        $form = new Form();
        $form->add($uploadcare_widget);
        $form->add(array('name' => 'submit',
          'attributes' => array(
            'type'  => 'submit',
            'value' => 'Upload!'
        )));

        return array(
          'form' => $form,
          'uploadcare' => $uploadcare,
        );
    }
}

```

Now we can display a form with a widget inside view:

```
