开发者

Routing Problem With Symfony

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. Si开发者_如何学运维nce 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!


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()) ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜