Check the database before goto controller

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

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.

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.

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

thanks Vince

I will try this

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.

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

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

Must have been dreaming … you’re right of course :)