1

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_empty: 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

whamsicore
  • 8,320
  • 9
  • 40
  • 50
  • please show all columns for those rows – xzyfer Feb 06 '11 at 08:46
  • 3
    Did you check if everything is actually in the table? Loading fixtures removes previous content. – Jakub Zalas Feb 06 '11 at 09:58
  • Yea, everything is in the table. I might add that I can access them directly no problem. They simply don't get returned when I'm using getRoute()->getObject(); Could it be something with using :name in the routing? – whamsicore Feb 07 '11 at 01:06
  • You should set the method_for_query option and define a method to call there to get the object(s). – Adam Arold Feb 22 '11 at 10:53
  • May be it's about the attribute "name" itself. You should use a slug to construct your URL. Some hidden spaces at the end of the string or special chars could cause this bug. – Timothée Martin Jun 13 '11 at 09:57

1 Answers1

1

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.

maectpo
  • 814
  • 2
  • 10
  • 22