Symfony/Doctrine: issue with $this->getRoute()->getObject, only some records being retrieved
Post table:
id name content
1 test1 generated from fixture
2 test2 generated
3 test3 generated
4 post1 this is actual post
5 post2 real
Routing:
post_show:
url: /:name
class: sfDoctrineRoute
options: { model: Posts, type: object, allow_empt开发者_运维百科y: true}
param: { module: post, action: show, name:test1}
Using $this->getRoute()->getObject();
in the action will return object fine for example.com/test1, example.com/test2, example.com/test3, will return nothing for all other queries (e.g. example.com/post1). What could be causing this?
* I believe the only difference between the records that are returned(test records) and the ones that don't(post) is that the test records were generated from my fixture
Look at my example:
routing.yml
book_list:
url: /api/books.:sf_format
class: sfDoctrineRoute
options: { model: Book, type: list, method: getActiveWithAuthor }
param: { module: book, action: list, sf_format: json }
requirements:
sf_format: (?:json|html)
actions.class.php
public function executeList(sfWebRequest $request) {
$this->books = BookTable::getActiveWithAuthor($request->getGetParameters());
}
BookTable.class.php
public static function getActiveWithAuthor(array $parameters) {
$bookQuery = BookQuery::create()
->addSelf()
->addAuthor();
if(isset($parameters['date_from']))
$bookQuery->andWhere('b.updated_at > ?', $parameters['date_from']);
return $bookQuery->execute();
}
This is just example, but it shows how it works. Use type: list, method: yourQueryMethod and so on.
精彩评论