title: How to separate php mvc controller directories for backend directory and frontend directory?
body: <p>I am struggling to separate controller directories that are responsible for backend controller and frontend controller so it can be easy for working with two parties of the application.
  I use this directory structure.</p>
  <pre><code>    |APP( DIRECTORY )
      |---CONTROLLERS
              |-Home.php
              |-Error.php
      |---CORE
            |-Application.php
            |-Controller.php
      |---MODEL
            |-User.php
      |---PUBLIC
            |-index.php
            |.htaccess
  </code></pre>
  <p>I want to be able to create backend and frontend contollers directories like this.</p>
  <pre><code>    |---CONTROLLERS
          |---FRONTEND
                  |-Somecontoller.php
          |---BACKEND
                  |-Somecontoller.php|APP( DIRECTORY )
  </code></pre>
  <p>Thanks in advance.</p>
  <p>// Application</p>
  <pre><code>   &lt;?php 
  
      class Application
      {
          public $url = null;
          public $controller = null;
          public $controllerPath = '../CONTROLLERS/';
          public $modelPath = '../MODELS/';
          public $errorFile = 'Err.php';
          public $defaultFile = 'Home.php'; 
  
          public function BootApp() 
          {
              $this-&gt;parseUrl();
  
              if (empty($this-&gt;url[0])) 
              {
                $this-&gt;loadDefaultController();
                return false;
              }  
  
              $this-&gt;loadExistingController();
              $this-&gt;callControllerMethod(); 
          }
  
          public function setController($path)
          {
              $this-&gt;controllerPath = trim($path, '/') . '/';
          }
  
          public function setModel($path)
          {
              $this-&gt;modelPath = trim($path, '/') . '/';
          }
  
          public function parseUrl()
          {
              $this-&gt;url = isset($_GET['url']) ? $_GET['url'] : null;
              $this-&gt;url = str_replace('-', '', $this-&gt;url);
              $this-&gt;url = filter_var($this-&gt;url, FILTER_SANITIZE_URL);
              $this-&gt;url = rtrim($this-&gt;url, '/');
              $this-&gt;url = explode('/', $this-&gt;url);
          }
  
          public function loadDefaultController()
          {
              require $this-&gt;controllerPath . $this-&gt;defaultFile;
              $this-&gt;controller = new Home();
              $this-&gt;controller-&gt;index();
          }
  
          public function loadExistingController()
          {
              $file = $this-&gt;controllerPath . $this-&gt;url[0] . '.php';
              if (file_exists($file)){
                    require $file;
                    $this-&gt;controller = new $this-&gt;url[0];
              } 
              else{
                    $this-&gt;error();
              }
          }
  
          public function callControllerMethod()
          {
              $this-&gt;controller-&gt;index(); 
          }
  
  
  
          private function error() 
          {
              require realpath($this-&gt;controllerPath . $this-&gt;errorFile);
              $this-&gt;controller = new Err();
              $this-&gt;controller-&gt;index();
              exit;
          }
      }
  }
  </code></pre>
  <p>// PUBLIC / .htaccess</p>
  <pre><code>   &lt;IfModule mod_rewrite.c&gt;
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-l
        RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
     &lt;/IfModule&gt;
  </code></pre>
  <p>// PUBLIC / index.php
  &lt;?php</p>
  <pre><code>    // SPL AUTOLOAD CORE, CONTROLLERS, MODELS
      $app = new Application();
      $app-&gt;BootApp();
      $app-&gt;setController('../CONTROLLERS/');
  </code></pre>