Development

Changeset 22782

You must first sign up to be able to contribute.

Changeset 22782

Show
Ignore:
Timestamp:
10/05/09 07:46:28 (4 years ago)
Author:
Jonathan.Wage
Message:

[1.3][sfDoctrinePlugin 2.0] Adding documentation for using the repository classes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfDoctrinePlugin/branches/1.3-2.0/README

    r22779 r22782  
    4949          length: 255 
    5050 
     51## Custom Repository Class 
     52 
     53You can configure a custom repository class so you can add new methods for 
     54executing and retrieving queries. 
     55 
     56    [yml] 
     57    Models\User: 
     58      type: entity 
     59      table: user 
     60      repositoryClass: UserRepository 
     61    # ... 
     62 
     63Now define a `UserRepository` class: 
     64 
     65    [php] 
     66    class UserRepository extends EntityRepository 
     67    { 
     68      public function getActiveUsers() 
     69      { 
     70        $qb = $this->createQueryBuilder('u'); 
     71        $q = $qb->getQuery(); 
     72 
     73        return $q->execute(); 
     74      } 
     75    } 
     76 
     77Now you can use this method like the following: 
     78 
     79    [php] 
     80    $repository = $em->getRepository('Models\User'); 
     81    $users = $repository->getActiveUsers(); 
     82 
     83If you utilize the `ActiveEntity` extension you can do the following: 
     84 
     85    [php] 
     86    $users = \Models\User::getActiveUsers(); 
     87 
     88In order to use the above syntax your `User` model needs to extend `sfDoctrineActiveEntity` 
     89like the following: 
     90 
     91    [php] 
     92    namespace Models; 
     93 
     94    use sfDoctrineActiveEntity; 
     95 
     96    class User extends sfDoctrineActiveEntity 
     97    { 
     98      // ... 
     99    } 
     100 
    51101## Data Fixtures 
    52102