Build a PHP MVC Application: Routing (Part 4/9)
Why Stack Overflow recommends it
Stack Overflow users cite it as the tutorial they were following when their .htaccess rewrite rules or URL parsing did not behave as shown, so it appears in debugging questions.
Recommended by 0 people across 0 different months, 2014 to 2016.
What it is
Part 4 of a nine-part Codecourse series on building a PHP MVC framework from scratch. It covers routing: using an .htaccess rewrite to pass the URL to index.php as a query string, then parsing it in an App class to pick the controller, method and parameters.
What people said
Cites NickC · 2014-08 · Stack Overflow · on “Rewriting the URL to echo out in a $_GET variable”
I'm following a YouTube tutorial ( [this video] ) and can't proceed any further without solving this problem. I've spent hours trying to fix it and have got no where. What I'm trying to do is pass the URL as a query string to then be fed back into an App function to be echoed out even if it doesn't exist. I've written an .htaccess file to rewrite a URL so that it can do this but for whatever reason it's not working like the video shows. In theory I should be able to type: localhost/mvc/public/a/b/c/d and have it echo out a/b/c/d Here's my .htaccess file: Options -MultiViews RewriteEngine On RewriteBase /localhost/mvc/public RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f R
Cites Luke Trout · 2016-03 · Stack Overflow · on “PHP7 MVC Echo not working - Mamp”
Complete Noob. I'm trying to learn MVC. Going through this tutorial: [this video] My Echo isn't printing on the screen. Here's my code (99% the same as tutorial above) Folder Structure app -controllers -home.php -core -App.php -Controller.php -models -views -init.php public -index.php -css index.php <?php require_once '../app/init.php'; $app = new App; init.php <?php require_once 'core/App.php'; require_once 'core/Controller.php'; App.php <?php class App { protected $controller ='home'; protected $method = 'index'; protected $params = []; public function _construct() { //$this->parseUrl(); echo 'hi'; } public function parseUrl() { if(isset($_Get['url'])){ echo $_Get['url']; } } } Controller.php <
Cites Jordan · 2016-06 · Stack Overflow · on “mod-rewrite RewriteBase not working correctly from root”
Hi I have been following the "Build a PHP MVC Application" [this video] tutorial on Codecourse's YouTube Channel. I have moved the project to the root(htdocs) and now when I load [LINK] all I see is the default apache folder index. My files are organised as such: htdocs ->app ->public ->.htaccess .htacces contains: Options -MultiViews RewriteEngine On RewriteBase /public/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] Edit: if I go to localhost/home (one of the controllers i setup) it loads the page correctly