I am attempting to put my new OOP skills to the test and am eventually going to build a simple OOP login/registration system.
However as I am making use of OOP I have decided to make my own simple MVC.
Here is my layout of my directory
root-directory/
.htaccess
app/
Config/
Controllers/
Models/
Views/
Lib/
Vendor/
composer.json
bootstrap/
app.php
public/
assets/
js/
css/
img/
index.php
.htaccess
I have my app file in the Bootstrap folder I have written my code in a manor so it checks if the _GET super variable has anything in it, if it doesn't then set the $this->controller = 'home' and set the $this->method = 'index'
Here is my Bootstrap/app.php file
<?php
namespace App\Bootstrap;
require __DIR__ . '/../Lib/vendor/autoload.php';
class App
{
private $controller;
private $method;
private $requests;
public function __construct($requests)
{
$this->requests = $requests;
$this->requests = $this->requests['PATH_INFO'];
$this->requests = explode('/',$this->requests);
if ($this->requests[0] == '')) {
$this->controller = 'home';
} else {
$this->controller = $this->requests[0];
}
if ($this->requests[1] == '' ) {
$this->method = 'index';
} else {
$this->method = $this->requests[1];
}
echo $this->controller;
echo '<br/>';
echo '<br/>';
echo $this->method;
die();
}
}
Here is my index.php file
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
require __DIR__ . '/../app/Bootstrap/app.php';
$b = new \App\Bootstrap\App($_GET);
Here is my .htaccess file
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?PATH_INFO=$1 [L,QSA]
</IfModule>
Is this a correct way of starting this project? As my next step would be to create a base controller and then link the url to the controller.
If this is not a correct/appropriate coding manor for OOP would a good correction include changing the RewriteRule to include to variables for the controller and method.