开发者

method_for_query , redirect to custom page

HI! I use symfony 1.4.11. 开发者_JAVA百科In my project's all users ad, are available on the site only when it owner will have a premium account.The problem is that all ads are available on direct links...So I use decision of this problem from day 6 of Jobbet. Routing:

ads_show_user:
  url:     /:sf_culture/ads/:slug
  class:   sfDoctrineRoute
  options: { model: Ads, type: object,  method_for_query: retrievePayAd }
  param:   { module: ads, action: show }
  requirements:
    sf_method: [get]
    sf_culture: (?:de|en|ru)

Model:

public function retrievePayAd(Doctrine_Query $q)
  {
    $q ->leftJoin('a.Owner o')
      ->leftJoin('o.Profile p')
      ->andWhere('p.payed_until > NOW()')
      ->andWhere('a.active = ?',1)
      ->andWhere('a.expires_at > NOW()');

    return $q->fetchOne();
  }

And all works fine, but next problem, that if owner of ad have not pay for premium, he can not see extended version of his ad too, like all users... Is it possible to redirect user not to 404 page, but to other page, where I can say user, why he can not see extended version of his ad ? Or is there other way that owner of ad can see extended version ? Thank you !


Yes, it's possible.

Modify your route to allow empty objects to be returned:

ads_show_user:
  ...
  options: { allow_empty: true ... }

Now, in your action, when you call $this->getRoute()->getObject(), it will not 404 if an object isn't found. You can then handle this case (or cases), however you wish.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜