As for the criticism in my post, I thought I would post a post about how I tend to create an MVC pattern in PHP
In PHP, I put the framework in several sections, because some of them are normal when it comes to MVC.
Primaries:
Secondaries - ModelLayer
- ViewLoader
- Library
- ErrorLayer
Inside the controller, I usually allow everyone access to the secondary layers, and View and Model from Primary.
This is how I structured it
|---------| |------------| |------------| | Browser | ----> | Controller | ----> | Model | |---------| |------------| |------------| | | | | | | |----------------| | | | |------------| -------------| View | |------------|
From my diagram, usually bypass the View <-> Model connection and execute the Controller <-> Model , and then the link from the Controller <-> View assigns the data.
In my framework, I try to create an object storage system so that I can easily retrieve objects, etc. An example of my object store looks like this:
class Registry { static $storage = array(); public static function get($key) { return isset(self::storage[$key]) ? self::storage[$key] : null; } public static function set($key,$object) { self::"storage[$key] = $object; } }
Somewhat more advanced than the path, so when I initialize the objects for the first time, I store them as Registry::set("View",new View()); to always be available.
So, in my controller, witch is the base controller, I create some magic methods __get() __set() , so that any class that extends the controller, I can easily return the request, for example:
abstract class Controller { public function __get($key) {
And user controller
class Controller_index extends Controller { public function index() { $this->View->assign("key","value");
The model will also be placed in the registry, but only allowed to be called from ModelLayer
class Model_index extends ModelLayer_MySql { }
or
class Model_index extends ModelLayer_MySqli { }
or file system
class Model_file extends ModelLayer_FileSystem { }
so that each class can be specific to the type of storage.
This is not a traditional type of MVC pattern, but it can be called Adoptive MVC.
Other objects, such as View Loader, should not be placed in the registry, as they are not specifically intended for users, but are used by other objects, such as View
abstract class ViewLoader { function __construct($file,$data) //send the file and data {
since the template file is included in the View loader, and not the View class, it separates user methods from system methods, and also allows you to use methods in the views themselves for general logic.
An example template file.
<html> <body> <?php $this->_include("another_tpl_file.php"); ?> <?php if(isset($this->session->admin)):?> <a href="<?php echo $this->MakeUri("user","admin","panel","id",$this->session->admin_uid) ?>"><?php echo $this->lang->admin->admin_link ?></a> <?php endif; ?> </body> </html>
I hope my examples will help you understand this a little more.