I am using PHP. I want to create an MVC setup from scratch to learn more about how MVC works. I want to use clean urls with slashes as delimiters for the arguments. How do people do this when it comes to GET method forms? Or do people avoid GET method forms all together?
As of right now the ways I can imagine are:
Any suggestions or suggested reading welcome.
You can use a .htaccess
file like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
So... if the url is
http://example.com/controller/action/param1/
you can path the controller and the action, the index.php receive the var url [string]
and you can split them to load the controller...like
$params = explode('/', $_GET['url']);
$controller = new $params[0];//load the controller
$controller->$params[1]($params[2]);//ejecute the method, and pass the param
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With