Help - Search - Members - Calendar
Full Version: [PHP] URLs and MVC
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
Killswitch
Hey guys, having a bit of a time. I am learning to work with MVC. I have everything working fine, but I would like to rewrite the urls a little more friendly than what they are. For example...

site.com/control/view/id/5 => site.com/control/the-page

I really am not sure how to go about this, since the view/id is relied upon to determine which method is being called. Since this could vary, I'm not sure if I used mod_rewrite to remove this if it would be able to determine everything correctly or not.

Does anyone have any experience in this field that could help point me in the right direction?
NGPixel
I would suggest you look at frameworks like CodeIgniter which does exactly that.

http://codeigniter.com/

Then you don't have to worry about the linking. The right controller and method will be called depending on the url (along with the parameters).

If you wish to use your own code, then you will need to either create routes in your code to call the right method from the URL or use mod_rewrite with defined rules.
Hayden
I would suggest looking into CodeIgniter or something similar like NGPixel stated but if you want to build it yourself...

I was curious myself once and took the wordpress htaccess and echo'd the $_GET and $_SERVER arrays to get an idea how the information was being passed to index.php.

CODE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.