Studied two days opencart, the realization principle of which makes a summary, and you discuss together under:
OpenCart is a self-developed architecture, and its implementation is based on a way of MVC, the core of the architecture under System/engine, including several files,
1): controller.php base class for all controllers
2): action.php action turn, that is, the path, such as the catalog under the class controlleraccountaddress is for account/address
3): front.php Front-end action execution file, this is on the basis of action.php operation, that is, equivalent to action.php is loaded data, and front.php is the action, responsible for execution.
4): loader.php This is the loading of the relevant class library files, including the database under the model, under the library file, the call method is $this->load->library ("file name under the library")
Other reference loader.php files, such as model, $this->load->model ("account/address");
5): model.php This file is the base class for all the model and is not described in more details.
6): registry.php The implementation of this file is the same as model.php, this class registry is the information center of the whole system, Registry is a singleton (Singleton), in the index.php start page,
First, the class instance is created as the classes to be used for the value of the constructor parameter, and the class instance is then set to this "registry".
The registry is like a shared data bus that concatenates modules/data together.
There are some public classes under system, so both the base class and the public class are loaded through index.php, that is, registry is registered, so you can load the classes and files you need.
Var_dump ($registry); exit; the content printed on the index.php setting Breakpoints (Interception section) is displayed as follows:
Object (Registry) [1]
Private ' data ' =
Array
' Load ' =
Object (Loader) [2]
Protected ' Registry ' =
&object (Registry) [1]
' Config ' =
Object (Config) [3]
Private ' data ' =
Array
...
' db ' = =
Object (DB) [4]
Private ' driver ' =
Object (MySQL) [5]
...
' url ' = =
Object (URL) [8]
Private ' url ' = null
Private ' SSL ' = null
Private ' rewrite ' =
Array
...
' Log ' =
Object (LOG) [9]
Private ' filename ' = = String ' Error.txt ' (length=9)
' Request ' =
Object (Request) [10]
Public ' get ' =
Array
...
Public ' post ' =
Array
...
Public ' cookie ' =
Array
...
Public ' files ' =
Array
...
Public ' server ' =
Array
...
Public ' request ' =
Array
...
' Response ' =
Object (Response) [11]
Private ' headers ' =
Array
Print_r ($registry->get (' config ')->get (' Account_module '); exit; This is the content that prints a single property
The following examples illustrate:
The declaration of the Registry.php class is as follows:
Final class Registry {
Private $data = Array ();
Public function Get ($key) {
Return (Isset ($this->data[$key]) $this->data[$key]: NULL);
}
Public function set ($key, $value) {
$this->data[$key] = $value;
}
Public function has ($key) {
return Isset ($this->data[$key]);
}
}
The controller's declaration is as follows (intercept section):
Abstract class Controller {
protected $registry;
protected $id;
protected $layout;
protected $template;
Protected $children = Array ();
Protected $data = Array ();
protected $output;
Public function __construct ($registry) {
$this->registry = $registry;
}
Public Function __get ($key) {
return $this->registry->get ($key);
}
Public Function __set ($key, $value) {
$this->registry->set ($key, $value);
}
}
Declare some variables arbitrarily:
$arr =array ("Mantis" and "task", "Hefei" = "Anhui");
$str = "Hefei, Anhui, China";
Declare a class:
Class db{
Private $xx = ' 123456 ';
Private $data =array ();
Public function Get ($key) {
Return (Isset ($this->data[$key]) $this->data[$key]: $key);
}
function Connect () {
Echo ' You're connecting ... ';
}
}
Declares a control class:
Class Controlleraccountfix extends controller{
var $name;
var $age;
var $key = ' Opencat ';
function __construct () {
$this->name= ' C ';
$this->age= ' 12 ';
}
function fix () {
Echo $this->key. Php_eol;
}
}
Declaring a registration class
$reg =new Registry ();
Registering these data becomes a public part:
$reg->set ("arr", $arr);
$reg->set ("str", $STR);
$reg->set ("Class", New Controlleraccountfix ());
$reg->set ("DB", New db ());
$controller = new Controlleraccountfix ($reg);
if (is_callable (Array ($controller, ' fix '))) {
$action = Call_user_func_array (Array ($controller, ' fix '), array (' dddd '));
}
The above code outputs OpenCart.
To rewrite the control class:
Class Controlleraccountfix extends controller{
protected $registry; Www.2cto.com
function fix () {
echo $this->db->get (' xx '); Output 123456
echo $this->db->connect ();//Output connecting ...
}
}
http://www.bkjia.com/PHPjc/477963.html www.bkjia.com true http://www.bkjia.com/PHPjc/477963.html techarticle studied two days opencart, the realization principle of which makes a summary, and you discuss the following: OpenCart is its own development of a set of architecture, the realization of the idea is based on a way of MVC, ...