Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaytaph/MultiParamBundle
MultiParam Annotation Bundle
https://github.com/jaytaph/MultiParamBundle
Last synced: 3 months ago
JSON representation
MultiParam Annotation Bundle
- Host: GitHub
- URL: https://github.com/jaytaph/MultiParamBundle
- Owner: jaytaph
- License: mit
- Archived: true
- Created: 2012-07-20T19:10:44.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2012-08-01T16:17:38.000Z (almost 12 years ago)
- Last Synced: 2024-01-22T08:32:47.604Z (5 months ago)
- Language: PHP
- Size: 261 KB
- Stars: 16
- Watchers: 7
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-symfony - MultiParamBundle - MultiParam Annotation Bundle. (Miscellaneous)
- awesome-symfony - MultiParamBundle - MultiParam Annotation Bundle. (Miscellaneous)
README
NoxLogicMultiParamBundle
========================This bundle provides enables the @MultiParamConverter. It's similar to the [@paramConvert annotation](http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html),
except for the following additional features:- You can add multiple converters in one action.
- You can customize the slug name
- You can customize the entity method for fetching the slug## Installation
Installation takes just few easy steps:
### Step 1: Add the bundle to your composer.json
If you're not yet familiar with Composer see http://getcomposer.org.
Add the MultiParamBundle in your composer.json:```js
{
"require": {
"noxlogic/multiparam-bundle": "2.1.*"
}
}
```**Warning:**
> if you use Symfony 2.0 the require value should be 2.0.*Now tell composer to download the bundle by running the command:
``` bash
php composer.phar update noxlogic/multiparam-bundle
```### Step 2: Enable the bundle
Enable the bundle in the kernel:
``` php
_id". If that slug isn't available, it will default to
the "id" slug.If you need another name, you can supply this in the options:
/**
* @route("/acme/country/{iso3}/airport/{iatacode}")
*
* @multiParamConverter("airport", class="AcmeBundle:Airport", options={"id = "iatacode"})
* @multiParamConverter("country", class="AcmeBundle:Country", options={"id = "iso3"})
*/
public function showAction(Country $country, Airport $airport) { ... }### Customize entity fetch method
It's possible to fetch an entity from something else than the primary key. When no additional options are given, this
is the default behaviour, but finding entities on other properties is also possible:/**
* @route("/acme/country/{iso3}/airport/{iatacode}")
*
* @multiParamConverter("airport", class="AcmeBundle:Airport", options={"id = "iatacode", "method" = "findOneByIataCode"})
* @multiParamConverter("country", class="AcmeBundle:Country", options={"id = "iso3", "method" = "findOneByIso3Code"})
*/
public function showAction(Country $country, Airport $airport) { ... }### Customize entity manager
If you have multiple entity managers and you want to use a non-default entitymanager, you can supply the
'entity_manager' option in order to change which manager is used./**
* @route("/acme/{post_id}")
* @multiParamConverter("post", class="AcmeBundle:Post", options = {"entity_manager" = "foo"})
*/
public function showAction(Post $post) {As with the default paramConverter, if you use typehinting AND you only need to use the default options, you can omit
the @MultiParamConverter annotation alltogether. Both examples are identical:/**
* @route("/acme/{post_id}")
* @multiParamConverter("post", class="AcmeBundle:Post")
*/
public function showAction(Post $post) {/**
* @route("/acme/{post_id}")
*/
public function showAction(Post $post) {## More info
Read more about this converter on its [official homepage](http://www.noxlogic.nl/), and do not hesitate to contact me
for issues and/or bug(fixes). PR's are always welcome!Special thanks to CruiseTravel, for whom this converter was originally written and allowed to open-source the code.