Check the database before goto controller
Posted 26 April 2010 - 11:53 PM
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.
Posted 27 April 2010 - 12:46 AM
Can you be more precise?
Note that you can forward or redirect to another controller-action if needed.
Posted 27 April 2010 - 01:08 AM
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.
Posted 27 April 2010 - 01:19 PM
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.