PHPackages                             mmoreram/controller-extra-bundle - 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. [Framework](/categories/framework)
4. /
5. mmoreram/controller-extra-bundle

ActiveSymfony-bundle[Framework](/categories/framework)

mmoreram/controller-extra-bundle
================================

Some specific controller annotations

v2.0.3(8y ago)151217.3k—0%16[3 issues](https://github.com/mmoreram/ControllerExtraBundle/issues)[1 PRs](https://github.com/mmoreram/ControllerExtraBundle/pulls)5MITPHPPHP &gt;=7.1

Since Mar 16Pushed 8y ago7 watchersCompare

[ Source](https://github.com/mmoreram/ControllerExtraBundle)[ Packagist](https://packagist.org/packages/mmoreram/controller-extra-bundle)[ Docs](https://github.com/mmoreram/ControllerExtraBundle)[ RSS](/packages/mmoreram-controller-extra-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (26)Used By (5)

ControllerExtra for Symfony2
============================

[](#controllerextra-for-symfony2)

[![Build Status](https://camo.githubusercontent.com/a5614daf5cbcbbe52c41d45e86617597b89e9d432d0bbce11c6c936111214555/68747470733a2f2f7472617669732d63692e6f72672f6d6d6f726572616d2f436f6e74726f6c6c6572457874726142756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/mmoreram/ControllerExtraBundle)

This bundle provides a collection of annotations for Symfony2 Controllers, designed to streamline the creation of certain objects and enable smaller and more concise actions.

Table of contents
-----------------

[](#table-of-contents)

1. [Reference](#reference)
2. [Entity Provider](#entity-provider)
    - [By namespace](#by-namespace)
    - [By doctrine shortcut](#by-doctrine-shortcut)
    - [By parameter](#by-parameter)
3. [Controller Annotations](#controller-annotations)
    - [@CreatePaginator](#-createpaginator)
        - [Paginator Entity](#paginator-entity)
        - [Paginator Page](#paginator-page)
        - [Paginator Limit](#paginator-limit)
        - [Paginator OrderBy](#paginator-orderby)
        - [Paginator Wheres](#paginator-wheres)
        - [Paginator Left Joins](#paginator-left-joins)
        - [Paginator Inner Joins](#paginator-inner-joins)
        - [Paginator Not Nulls](#paginator-not-nulls)
        - [Paginator Attributes](#paginator-attributes)
        - [Paginator Example](#paginator-example)
        - [Pagerfanta Add-on](#pagerfanta-add-on)
        - [KNPPaginator Add-on](#knppaginator-add-on)
    - [@LoadEntity](#-loadentity)
        - [Entity Mapping](#entity-mapping)
        - [Entity Mapping fallback](#entity-mapping-fallback)
        - [Entity Repository](#entity-repository)
        - [Entity Factory](#entity-factory)
    - [@CreateForm](#-createform)
    - [@Flush](#-flush)
    - [@ToJsonResponse](#-tojsonresponse)
    - [@Log](#-log)
    - [@Get](#-get)
    - [@Post](#-post)
4. [Custom annotations](#custom-annotations)
    - [Annotation](#annotation)
    - [Resolver](#resolver)
    - [Definition](#definition)
    - [Registration](#registration)

Reference
=========

[](#reference)

By default, all annotations are loaded, but any individual annotation can be completely disabled by setting to false `active` parameter.

Default values are:

```
controller_extra:
    resolver_priority: -8
    request: current
    paginator:
        active: true
        default_name: paginator
        default_page: 1
        default_limit_per_page: 10
    entity:
        active: true
        default_name: entity
        default_persist: true
        default_mapping_fallback: false
        default_factory_method: create
        default_factory_mapping: true
    form:
        active: true
        default_name: form
    object_manager:
        active: true
        default_name: form
    flush:
        active: true
        default_manager: default
    json_response:
        active: true
        default_status: 200
        default_headers: []
    log:
        active: true
        default_level: info
        default_execute: pre
```

> ResolverEventListener is subscribed to `kernel.controller` event with priority -8. This element can be configured and customized with `resolver_priority` config value. If you need to get ParamConverter entities, make sure that this value is lower than 0. The reason is that this listener must be executed always after ParamConverter one.

Entity provider
===============

[](#entity-provider)

In some annotations, you can define an entity by several ways. This chapter is about how you can define them.

By namespace
------------

[](#by-namespace)

You can define an entity using its namespace. A simple new `new()` be performed.

```
/**
 * Simple controller method
 *
 * @SomeAnnotation(
 *      class = "Mmoreram\CustomBundle\Entity\MyEntity",
 * )
 */
public function indexAction()
{
}
```

By doctrine shortcut
--------------------

[](#by-doctrine-shortcut)

You can define an entity using Doctrine shortcut notations. With this format you should ensure that your Entities follow Symfony Bundle standards and your entities are placed under `Entity/` folder.

```
/**
 * Simple controller method
 *
 * @SomeAnnotation(
 *      class = "MmoreramCustomBundle:MyEntity",
 * )
 */
public function indexAction()
{
}
```

By parameter
------------

[](#by-parameter)

You can define an entity using a simple config parameter. Some projects use parameters to define all entity namespaces (To allow overriding). If you define the entity with a parameter, this bundle will try to instance it with a simple `new()` accessing directly to the container ParametersBag.

```
parameters:

    #
    # Entities
    #
    my.bundle.entity.myentity: Mmoreram\CustomBundle\Entity\MyEntity
```

```
/**
 * Simple controller method
 *
 * @SomeAnnotation(
 *      class = "my.bundle.entity.myentity",
 * )
 */
public function indexAction()
{
}
```

Controller annotations
======================

[](#controller-annotations)

This bundle provide a reduced but useful set of annotations for your controller actions.

@CreatePaginator
----------------

[](#createpaginator)

Creates a Doctrine Paginator object, given a request and a configuration. This annotation just injects into de controller a new `Doctrine\ORM\Tools\Pagination\Pagination` instance ready to be iterated.

You can enable/disable this bundle by overriding `active` flag in configuration file `config.yml`

```
controller_extra:
    pagination:
        active: true
```

> By default, if `name` option is not set, the generated object will be placed in a parameter named `$paginator`. This behaviour can be configured using `default_name` in configuration.

This annotation can be configured with these sections

### Paginator Entity

[](#paginator-entity)

To create a new Pagination object you need to refer to an existing Entity. You can check all available formats you can define it just reading the [Entity Provider](#entity-provider) section.

```
