Question

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 !

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top