| 16 | | ++ The Query Registry |
| 17 | | |
| 18 | | Doctrine_Query_Registry is a class for registering and naming queries. It helps with the organization of your applications |
| 19 | | queries and along with that it offers some very nice convenience stuff. |
| 20 | | |
| 21 | | The queries are added using the add() method of the registry object. It takes two parameters, the query name and the actual |
| 22 | | DQL query. |
| 23 | | |
| 24 | | <code type="php"> |
| 25 | | $r = Doctrine_Manager::getInstance()->getQueryRegistry(); |
| 26 | | |
| 27 | | $r->add('all-users', 'FROM User u'); |
| 28 | | </code> |
| 29 | | |
| 30 | | +++ Namespaces |
| 31 | | |
| 32 | | The Query registry supports namespaces. The namespace is separated from the actual name with / -mark. If the name of the |
| 33 | | namespace is a record name the given record has all the named queries available in its local scope. |
| 34 | | |
| 35 | | <code type="php"> |
| 36 | | $r = Doctrine_Manager::getInstance()->getQueryRegistry(); |
| 37 | | |
| 38 | | $r->add('User/all', 'FROM User u'); |
| 39 | | $r->add('User/byName', 'FROM User u WHERE u.name = ?'); |
| 40 | | |
| 41 | | $userTable = Doctrine::getTable('User'); |
| 42 | | |
| 43 | | // find the user named Jack Daniels |
| 44 | | $user = $userTable->findOneByName('Jack Daniels'); |
| 45 | | |
| 46 | | // find all users |
| 47 | | $users = $userTable->find('all'); |
| 48 | | </code> |
| 49 | | |
| | 16 | ++ Named Queries |