0
\$\begingroup\$

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.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Voting to close since we don't review folder structures, just code. \$\endgroup\$
    – syb0rg
    Jul 13, 2016 at 13:01
  • \$\begingroup\$ @syb0rg sorry about that, will edit it once I got some code in it. \$\endgroup\$
    – mp252
    Jul 13, 2016 at 13:55

1 Answer 1

1
\$\begingroup\$
  1. You can add another folder named libraries inside of app.
  2. Follow a particular case convention. Like don't have config (all small) and other folders with first letter capitalized. Either all small or all first letter capitalized.
  3. Add a language folder within app. That will store your language strings within each language folder. For example, you can have a language/english folder & similarly for other languages.

I like that you have separated the public folder.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.