Update custom-repositories.md to use code highlighting

Looks better this way
This commit is contained in:
Sebastian Krebs 2014-11-21 14:21:26 +01:00
parent 2d8903a330
commit 1e2da2d84f

View file

@ -4,7 +4,7 @@ As well as the default repository you can create a custom repository for an enti
methods for particular searches. These need to extend `FOS\ElasticaBundle\Repository` to have methods for particular searches. These need to extend `FOS\ElasticaBundle\Repository` to have
access to the finder: access to the finder:
``` ```php
<?php <?php
namespace Acme\ElasticaBundle\SearchRepository; namespace Acme\ElasticaBundle\SearchRepository;
@ -23,37 +23,41 @@ class UserRepository extends Repository
To use the custom repository specify it in the mapping for the entity: To use the custom repository specify it in the mapping for the entity:
fos_elastica: ```yaml
clients: fos_elastica:
default: { host: localhost, port: 9200 } clients:
indexes: default: { host: localhost, port: 9200 }
website: indexes:
client: default website:
types: client: default
user: types:
mappings: user:
# your mappings mappings:
persistence: # your mappings
driver: orm persistence:
model: Application\UserBundle\Entity\User driver: orm
provider: ~ model: Application\UserBundle\Entity\User
finder: ~ provider: ~
repository: Acme\ElasticaBundle\SearchRepository\UserRepository finder: ~
repository: Acme\ElasticaBundle\SearchRepository\UserRepository
```
Then the custom queries will be available when using the repository returned from the manager: Then the custom queries will be available when using the repository returned from the manager:
/** var FOS\ElasticaBundle\Manager\RepositoryManager */ ```php
$repositoryManager = $container->get('fos_elastica.manager'); /** var FOS\ElasticaBundle\Manager\RepositoryManager */
$repositoryManager = $container->get('fos_elastica.manager');
/** var FOS\ElasticaBundle\Repository */ /** var FOS\ElasticaBundle\Repository */
$repository = $repositoryManager->getRepository('UserBundle:User'); $repository = $repositoryManager->getRepository('UserBundle:User');
/** var array of Acme\UserBundle\Entity\User */ /** var array of Acme\UserBundle\Entity\User */
$users = $repository->findWithCustomQuery('bob'); $users = $repository->findWithCustomQuery('bob');
```
Alternatively you can specify the custom repository using an annotation in the entity: Alternatively you can specify the custom repository using an annotation in the entity:
``` ```php
<?php <?php
namespace Application\UserBundle\Entity; namespace Application\UserBundle\Entity;
@ -69,4 +73,4 @@ class User
//--- //---
} }
``` ```