https://www.udemy.com/learn-php-mode...ecture/2201044
By idea if I try http://localhost/MVCfirst/public/
it should try to open index.php :
C:\Bitnami\wampstack-5.4.38-0\apache2\htdocs\MVCfirst\public\index.php
this file requires boostrap file ..\MVCfirst\app\start.php
The boostrap file requires \MVCfirst\vendor\autoload.php
which using composer loads project core functionality, contollers and apps, including file
C:\Bitnami\wampstack-5.4.38-0\apache2\htdocs\MVCfirst\app\core\App.php
Than on the second line index.php creates an instance of class App from App.php, which constructor should print “Hello world!”.
But than I try http://localhost/MVCfirst/public/ - nothing happens. I mean i do not see "Hello world" on the webpage.
http://localhost/MVCfirst/public/index.php -prints line: "Before requiring start.php, in index.php After requiring start.php, in index.php" Thus seems the mistake is in class initiation, because "Hello wold" and line After initiating class App, in index.php" is not printed.
If i try http://localhost - opens Bitnami welcome page
http://localhost/MVCfirst/ - opens page with directory structure
http://localhost/MVCfirst/public - page is empty, i do not see directory structure (there is css folder)
http://localhost/MVCfirst/app/ - again i can see directory structure with files.
I can not find where is my mistake, seems that url is not translated for method – action, or maybe class is not loaded and thus constructor does not execute.
The question is how to find the mistake and where is the mistake. How to debug MVC?
Directory structure
C:\Bitnami\wampstack-5.4.38-0\apache2\htdocs\MVCfirst
..\MVCfirst\composer.json
..\MVCfirst\app
..\MVCfirst\app\controllers
..\MVCfirst\app\core
..\MVCfirst\app\core\App.php
..\MVCfirst\app\models
..\MVCfirst\app\views
..\MVCfirst\app\start.php
..\MVCfirst\public
..\MVCfirst\public\css
..\MVCfirst\public\.htaccess
..\MVCfirst\public\index.php
..\MVCfirst\vendor
..\MVCfirst\vendor\composer with several files
..\MVCfirst\vendor\autoload.php
Related files:
C:\Bitnami\wampstack-5.4.38-0\apache2\htdocs\MVCfirst\public\index.php
Expand|Select|Wrap|Line Numbers
- <?php
- echo "Before requiring start.php, in index.php";
- require_once '../app/start.php';
- echo "After requiring start.php, in index.php";
- $app = new App();
- echo "After initiating class App, in index.php";
- ?>
<?php
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT .'/vendor/autoload.php';
?>
C:\Bitnami\wampstack-5.4.38-0\apache2\htdocs\MVCfirst\vendor\autoload.php
Expand|Select|Wrap|Line Numbers
- <?php
- // autoload.php @generated by Composer
- require_once __DIR__ . '/composer' . '/autoload_real.php';
- return ComposerAutoloaderInitb77b3134bd41be264b6a56ffd220713b::getLoader();
Expand|Select|Wrap|Line Numbers
- <?php
- class App {
- public function __construct(){
- echo 'Hello World';
- $this->parseUrl()
- }
- protected function parseUrl(){
- echo $_GET['url'];
- }
- }
- ?>
Expand|Select|Wrap|Line Numbers
- {
- "autoload": {
- "classmap": [
- "app/core",
- "app/models"
- ]
- }
- }
Expand|Select|Wrap|Line Numbers
- Options -MultiViews
- Options -Indexes
- RewriteEngine On
- RewriteBase /MVCfirst/public
- RewriteCond ${ENV:REDIRECT_STATUS} ^$
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-l
- RewriteRule ^(.+)$ index.php?url-$1 [QSA,L]