0

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!

ShoeLace1291
  • 4,551
  • 12
  • 45
  • 81
  • 1
    Are you writing your own MVC framework or using an extant one such as Yii? – Pete Jun 18 '12 at 07:31
  • How can the method be valid without the controller (class)??? – PeeHaa Jun 18 '12 at 07:34
  • Yes I am writing my own basic MVC framework... hence the word "custom" in the title" – ShoeLace1291 Jun 18 '12 at 08:01
  • And the method could be valid if there's no controller. Example: When I used codeigniter, I would have my about and contact pages as methods of my default controller class... So in query string url's terms it would look like index.php?controller=default&method=about but it would be accessed through example.com/about – ShoeLace1291 Jun 18 '12 at 08:06

1 Answers1

1

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?

Community
  • 1
  • 1
Luxspes
  • 6,268
  • 2
  • 28
  • 31
  • Sorry for being so blunt, but are you sure this article is up to date and follows current web development trends? It is from 2004, after all. – ShoeLace1291 Jun 18 '12 at 08:02
  • OTOH to be sincere, if you actually want to follow current web development trends you should be using a framework that already solves this... And you should probably be avoiding PHP: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ – Luxspes Jun 18 '12 at 22:00