PHPackages                             atans/atans-common - 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. atans/atans-common

ActiveLibrary

atans/atans-common
==================

AtansCommon for Zend Framework 2

0.1.4(12y ago)41014MITPHPPHP &gt;=5.3.3

Since Jul 18Pushed 11y ago1 watchersCompare

[ Source](https://github.com/atans/AtansCommon)[ Packagist](https://packagist.org/packages/atans/atans-common)[ Docs](https://github.com/atans/AtansCommon)[ RSS](/packages/atans-atans-common/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (4)Versions (6)Used By (0)

AtansCommon
===========

[](#atanscommon)

Master: [![Build Status](https://camo.githubusercontent.com/373cf9349b8ac0b96a8e22951f8af3826f18dad7bebfeb260c80ca67a6148017/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6174616e732f4174616e73436f6d6d6f6e2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/atans/AtansCommon)

The Atans library

- 0.1.1 (2013-8-4)
- 0.1.2 (2013-11-12)
- 0.1.3 Add two controller plugins (2013-12-16)
- 0.1.4 Update bootstrap alert (2013-12-19)

Contoller plugin
----------------

[](#contoller-plugin)

### Ajax plugin

[](#ajax-plugin)

```
    public function textAction()
    {
        // Text
        return $this->ajax()->html('html');
        // Content-Type: text/html
        // Output: html
    }

    public function textAction()
    {
        // Text
        return $this->ajax()->text('text');
        // Content-Type: text/plain
        // Output: text
    }

    public fucntion statusTestAction()
    {
        return $this->ajax()->status('ok', 'Ok message');
        // Content-Type: application/json
        // Output : {"status" : "ok", "message" : "Ok message"}

        return $this->ajax()->status('ok', 'Ok message', array('data' => 'Returns data'));
        // Output : {"status" : "ok", "message" : "Ok message", "data" => "Retruns data"}

        return $this->ajax()->status('ok', array('data' => 'Returns data'));
        // Output : {"status" : "ok", "data" => "Retruns data"}
    }

    public fucntion successTestAction()
    {
        return $this->ajax()->success(true, 'Ok message', array('data' => 'Returns data'));
        // Content-Type: application/json
        // output : {"success" : true, "message" : "Ok message", "data" => "Retruns data"}

        return $this->ajax()->success(false, 'False message');
        // Output : {"success" : false, "message" : "False message"}

        return $this->ajax()->success(true, array('data' => 'Returns data'));
        // Output : {"success" : true, "data" => "Retruns data"}
    }
```

### ObjectManager plugin

[](#objectmanager-plugin)

```
    public function indexAction()
    {
        $id = (int) $this->params()->formRoute('id', 0);

        // Default object manager is doctrine.entitymanager.orm_default
        $entity = $this->objectManager()->find('Application/Entity/EntityName', $id);
        // or
        $entity = $this->objectManager('doctrine.entitymanager.orm_other')->find('Application/Entity/EntityName', $id);
    }
```

### Translate plugin

[](#translate-plugin)

```
    public function indexAction()
    {
        $message = $this->translate('This is a message');

        // Same as
        $translator = $this->getServiceLocator()->get('Translate');
        $message    = $translator->translate('This is a message');
    }
```

String library
--------------

[](#string-library)

```
    echo \AtansCommon\Text\String::cut('This is a longer text', 6);
    // output : This i...
```

View widgets
------------

[](#view-widgets)

### Flash messenger Alert

[](#flash-messenger-alert)

Controller:

```
    public function indexAction()
    {
        $this->flashMessenger()
             ->setNamespace('application-index')
             ->addSuccessMessage('Message text');

        ...

        return array();
    }
```

View:

```
    //application/index/index.phtml
