opencart analysis_PHP tutorial
After studying opencart for two days, I will make a summary of its implementation principles and discuss it with you:
opencart is a self-developed architecture, and its implementation idea is also based on MVC. The core of the architecture is under system/engine, including several files,
1): controller.php The base class of all controllers
2): action.php Action steering, that is, path, for example, the class ControllerAccountAddress under catalog is for account/address
3): front.php Front-end action execution file, this is an operation based on action.php, which is equivalent to action.php loading data, and front.php is the action, responsible for execution.
4): loader.php This is to load related class library files, including files under database, model, and library. The calling method is $this->load->library("library File name ")
Other reference loader.php files, such as model, $this->load->model("account/address");
5): model.php This file is the base class of all models and will not be explained further.
6): registry.php The implementation of this file is the same as Model.php. This class Registry is the information center of the entire system. Registry is a singleton (Singleton). In the index.php start page,
First, pass the value of the class to be used as a constructor parameter to create a class instance, and then set this class instance to the "registry",
This registry is like a shared data bus, connecting various modules/data together.
There are some public classes under System, so the basic classes and public classes are loaded through index.php, which is registered by Registry, so that you can load the classes and files you need
var_dump($registry);exit; The content printed out by setting a breakpoint in index.php (the intercepted part) is shown 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; 这是打印单个属性的内容
下面用实例来说明:
registry.php类的声明如下:
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]);
}
}
controller的声明如下(截取部分):
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);
}
}
任意声明一些变量:
$arr=array("mantis"=>"task","hefei"=>"anhui");
$str="中国安徽合肥";
声明一个类:
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 are connecting...';
}
}
//声明一个控制类:
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;
}
}
//声明注册类
$reg=new registry();
注册这些数据成为公共的部分:
$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'));
}
//以上代码输出Opencart。
在把控制类重写一下:
class ControllerAccountFix extends Controller{
protected $registry; www.2cto.com
function fix(){
echo $this->db->get('xx'); //输出123456
echo $this->db->connect();//输出 you are connecting ...
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

Analysis of the role and principle of nohup In Unix and Unix-like operating systems, nohup is a commonly used command that is used to run commands in the background. Even if the user exits the current session or closes the terminal window, the command can still continue to be executed. In this article, we will analyze the function and principle of the nohup command in detail. 1. The role of nohup: Running commands in the background: Through the nohup command, we can let long-running commands continue to execute in the background without being affected by the user exiting the terminal session. This needs to be run

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

Title: Analysis of the reasons and solutions for why the secondary directory of DreamWeaver CMS cannot be opened. Dreamweaver CMS (DedeCMS) is a powerful open source content management system that is widely used in the construction of various websites. However, sometimes during the process of building a website, you may encounter a situation where the secondary directory cannot be opened, which brings trouble to the normal operation of the website. In this article, we will analyze the possible reasons why the secondary directory cannot be opened and provide specific code examples to solve this problem. 1. Possible cause analysis: Pseudo-static rule configuration problem: during use

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

Go language is a programming language with very powerful concurrency features. It uses the concept of goroutine to achieve concurrency, and also provides a wealth of tools and methods to deal with blocking. In the Go language, the implementation methods and advantages of blocking are important things we need to understand. This article will introduce the implementation method of blocking in Go language and its advantages, and provide specific code examples to help readers better understand. Implementation methods of blocking In the Go language, blocking can be implemented in a variety of ways, including channels, mutual
