Opencart analys_php tutorial

Source: Internet
Author: User
Tags opencart
Opencart analysis. I have studied opencart for two days and made a summary of its implementation principles. I will discuss with you that opencart is a self-developed architecture and its implementation idea is also based on MVC, I studied opencart for two days and summarized the implementation principles. I will discuss with you the following:


Opencart is a self-developed architecture, and its implementation idea is also based on MVC. The core of the architecture is system/engine, which includes several files,

1): the base class of all controllers of controller. php

2): action. php redirects, that is, the path. for example, the class ControllerAccountAddress under the catalog is

3): front. php front-end action execution file, which is in action. php-based operations, that is, action. php loads data, while front. php is an action and is responsible for execution.

4): loader. php: loads related class library files, including files under databases, models, and libraries, the call method is $ this-> load-> library ("file name under library").

For more information, see the loader. php file, such as model, $ this-> load-> model ("account/address ");

5): the model. php file is the base class of all models.

6): registry. php file implementation and Model. like php, Registry is the information hub of the entire system. Registry is a Singleton instance. on the php start page,
First, create a class instance as the class used to pass the value as the constructor parameter, and then set this class instance to this "registry,
This registry is like a shared data bus that concatenates modules and data.

There are some public classes in the System, so both the basic and public classes use the index. php to load, that is, Registry registration, so that you can load the classes and files you need.

Var_dump ($ registry); exit; in index. php, set the content (part truncated) to be printed by the breakpoint to the following:

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 'cookies' =>
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 prints the content of a single attribute

The following is an example:

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 statement is as follows (screenshot ):

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 any variables:

$ Arr = array ("mantis" => "task", "hefei" => "anhui ");
$ Str = "Hefei, Anhui, China ";

Declare a class:

Class db {
Private $ xx = '000000 ';
Private $ data = array ();
Public function get ($ key ){
Return (isset ($ this-> data [$ key])? $ This-> data [$ key]: $ key );
}

Function connect (){
Echo 'you are connecting ...';
}
}

// Declare 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;
}
}

// Declare the registration class


$ Reg = new registry ();

Register the data as 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 ('ddddd '));
}


// The above code outputs Opencart.


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 you are connecting...
}
}

Opencart is a self-developed architecture, and its implementation idea is also based on MVC ,...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.