문제

HI! I use symfony 1.4.11. 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top