Skip to main content
6 of 6
added 484 characters in body
Kid Diamond
  • 2.6k
  • 16
  • 35

Is this a good site structure? Do you have any tips/suggestions?

  • You might wanna create a new folder public / public_html to store all the application's public files for the web (javascripts, stylesheets, images, front-end controller, etc). Then you can set this folder as your web root so that the rest of your application code remains private. It also has the benefit of when the PHP module fails to load, only your front-end controller's code will be exposed. The rest will remain hidden.

  • I don't see a reason why you wouldn't merge config.php with index.php. They essentially do the same thing; bootstrapping the "framework".

  • May I suggest you to make use of a namespace based auto loader (e.g. the PSR-0 autoloader).

With this you don't have to keep adding new folders to your auto loader (referring to the long chain of else ifs in your current auto loader). Instead, you declare them via namespaces in your classes which makes it more efficient and handy. Additionally it prevents conflict between duplicate class names from different namespaces.

Notes

  • Your controllers are tightly coupled to their dependencies. I suggest you make use of Dependency Injection to couple them loosely. It also makes for easier testing.
  • Your Registry class introduces global state which goes against the principles of OOP and is considered an anti-pattern.

HTML code in the index.php bootstrap file is a big no no.

<a href="index.php?route=login">Login</a> <a href="index.php?route=register">Register</a>

Same goes for:

if($authService->login('[email protected]', 'testPass')) {
    $notice = 'Test logged In'; //<---
} else {
    $notice = 'Not logged in'; //<---
}

In the MVC pattern all View related logic goes in it's corresponding View class and HTML in the template.


In the show() method of your View class you're doing:

foreach ($this->vars as $key => $value) {
    $$key = $value;
}

Fortunately, extract() gets the job done with less code: extract($this->vars);.

---

Am I doing it right (according to the MVC model)?

The MVC pattern is all about separation of concerns. You've almost got that right. Make sure every type of logic resides in the appropriate layer, and you will be doing it right.

As far as the rest of your code (the "framework"), that's just detail that has nothing to do with the MVC pattern directly. The only thing it serves is to bootstrap itself so that you can utilize the MVC pattern in an easy, efficient manner.

Kid Diamond
  • 2.6k
  • 16
  • 35