views:

172

answers:

2

So I have a module that displays articles. And I tried to make an action that displayed all article of a certain publication when that publication was clicked. I tried following the way to do this on the symfony jobeet tutorials but I ran into some new headaches. Since publications and authors can sometime be url unfriendly, I want to use slugs, and this is where I ran into the problem.

So I have an article module and I added a routing rule like this

publication_articles:
  url:  /publications/:publication_slug
  class: sfDoctrineRoute
  param: { module: article, action: publication }
  options: { model: Article, type: list }

I then added a getPublicationSlug() function to the article class that took out spaces and special characters - nothing special.

I then added this function to the action class:

  public function executePublication(sfWebRequest $request)
  {
      $this->articles = $this->getRoute()->getObjects();
  }

When I try adding a link like this:

<a href="<?php echo url_for('publications/'.$article->getPublicationSlug()) ?>"><?php echo $article->getPublication() ?></a>

The page returns all the articles without any filtering on the publication

and if i add a link like this:

<?php echo link_to($article->getPublication(), 'publication_articles', $article) ?>

I get this error:

The "/publications/:publication_slug" route has some missing mandatory parameters (:publication_slug).

Any ideas? Thanks so much!

A: 

The object linking referenced in the Symfony guides (url_for('my_route', $obj)) has never worked properly for me. Instead I always generate my routes using direct parameter insertion, try this instead:

<?php echo link_to($article->getPublication(), '@publication_articles?publication_slug=' . $article->getPublicationSlug()) ?>
Cryo
While the above will fix your immediate issue it looks like you'll have a deeper problem next. After looking into the custom getter routing further it looks like this is not supported by Doctrine at all, only Propel. sfDoctrineRoute will only match on columns that actually exist in the table definition while sfPropelRoute uses reflection to allow for custom getters. You'll need to add your slug columns into your table definition to get this to work.
Cryo
Thanks for the help. That's weird bc this page says that this is supported by doctrine. http://www.symfony-project.org/jobeet/1_2/Doctrine/en/07
Daniel Hertz
I was using the same tutorial to implement it but I couldn't get it to work as they said so I dove into the actual sfDoctrinePlugin code and confirmed it. I'm hoping I'm wrong but I wrote a test implementation and couldn't get it to work. If you find a way to make it work please let me know.
Cryo
A: 

I really avoid using sfDoctrineRoute in such cases due to some additional joins that I want to implement, not just getting an object.

Darmen