Question

So, I am beginning the process of coding a PHP application website, which will be coded in the MVC architecture,but would like to implement the method of using Pretty URL's with it. Since I have never created my own Pretty URL code before, I'm not sure where to start. In the past, I would use query string URL's(I think that's the correct term to use) such as example.com/index.php?act=controller&sub=method&id=123456... With this website, I would prefer the URL's to be something more like example.com/controller/method/article-title/123456. But, like I said, I'm not even sure of where to start.

How would I point the URL correctly if... The method provided isn't found, is invalid, or not provided at all? example.com/controller/article-title/123456 (would point to example.com/provided-controller/default-method/page-title/123456

The method provided is found, is valid, and is provided, but no controller is found or is invalid or is not provided? example.com/article-title/123456 (should point to example.com/default-controller/provided-method/123456)

I hope I am being clear on everything and that you get what I'm talking about. Basically, I want to do something like the CodeIgniter URL Router system.

Thanks for your time!

Was it helpful?

Solution

Assuming you are not using an existing MVC framework that already gives you this, and that you want to create your own, my suggestion would be for you to implement a Front Controller. Here is a tutorial on how to do it: http://onlamp.com/pub/a/php/2004/07/08/front_controller.html

You can also take a look at an extremly simple example here: What is a Front Controller and how is it implemented in PHP?

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