Yii Framework Forum: Check the database before goto controller - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Check the database before goto controller Rate Topic: -----

#1 User is offline   Umut Gundogdu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 27-November 08
  • Location:Ankara

Posted 26 April 2010 - 11:53 PM

Hi,

My system needs to do following steps

1- Customer request a URL (mysite.com/site/myportfolio)
2- System checks the database if this URL stored into database
2.a. If yes get the content from database and display the user
2.b. If no run the site controller myportfolio action.

Anybody any idea how to check the database before I go to controller. Thanks.

Hope something in the config file can help me to achieve this request.

Thanks
Umut
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 27 April 2010 - 12:46 AM

Why not simply check within the controller action (site/myportfolio)? It seems to me you don't want dynamic controllers/actions? It seems you just want to load data if possible, otherwise fallback to default output.

Can you be more precise?

Note that you can forward or redirect to another controller-action if needed.
0

#3 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 27 April 2010 - 12:58 AM

You can actually create a custom component that extends the CUrlManager component class and in that custom class override the processRules() method and load the rules from the DB.
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#4 User is offline   Umut Gundogdu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 27-November 08
  • Location:Ankara

Posted 27 April 2010 - 01:08 AM

Thanks for quick reply.

In my system, my reseller can be able to edit or create their own pages and their own URL for that. This url can be mysite.com/myproducts. What I want is, my system first check this URL from database. If this URL exist than redirect to contentController to display this data, If it is not in URL like mysite.com/myshoppingCart, It goes Shoppingcart controller.

Hope I am clear this time.

Currently I am using ErrorHandler. Like mysite.com/myproducts. I don't have myproducts controller that a reason it throws error and than I direct to page errorAction and then I check the database in the errorAction. But I am not happy with this. Because if the real error comes up, I can't show properly.


Thanks
Umut
0

#5 User is offline   Umut Gundogdu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 27-November 08
  • Location:Ankara

Posted 27 April 2010 - 01:10 AM

thanks Vince

I will try this
0

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 27 April 2010 - 02:51 AM

Maybe it's easier to override beforeAction in your base components/Controller.php to perform the DB query. If found, you can return false to supress any action.
0

#7 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 27 April 2010 - 01:19 PM

View PostMike, on 27 April 2010 - 02:51 AM, said:

Maybe it's easier to override beforeAction in your base components/Controller.php to perform the DB query. If found, you can return false to supress any action.


Although this is an option, I think Vince's solution is more robust.
To use the beforeAction would require a beforeAction in every controller (so don't forget to add it to any new controllers).
Next to that, interpreting the url to decide whether to load it from db or not is a url management task, thus an UrlManager should take care of this.
0

#8 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 27 April 2010 - 01:43 PM

View PostOnman, on 27 April 2010 - 01:19 PM, said:

To use the beforeAction would require a beforeAction in every controller (so don't forget to add it to any new controllers).


Not if you do it in the base controller, like suggested.
0

#9 User is offline   Umut Gundogdu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 27-November 08
  • Location:Ankara

Posted 27 April 2010 - 08:32 PM

beforeAction method is not working because If the system can not find the controller, doesn't go this method. It throws 404 error.

Extrnding URLManagement works fine thanks all
0

#10 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 28 April 2010 - 02:12 AM

View Postumutau, on 27 April 2010 - 08:32 PM, said:

beforeAction method is not working because If the system can not find the controller, doesn't go this method. It throws 404 error.


Must have been dreaming ... you're right of course :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users