小编8th*_*son的帖子

在OpenCart中混淆类和方法调用

我有一个框架(OpenCart)Controller类(如:catalog/controller/product/product.php)代码如下:

class ControllerProductProduct extends Controller {
    public function index() {
      //some code
      $this->response->setOutput($this->render());
      //some more code
    }
}
Run Code Online (Sandbox Code Playgroud)

有一种表达方式$this->response->setOutput($this->render());.我知道这个表达式用于什么,但我对它的工作方式感到困惑.

$this指当前类,即ControllerProductProduct,它意味着$this->response对象必须存在于ControllerProductProduct其父类或其父类中Controller.但这种情况并非如此.这个对象实际上存在于父类的一个受保护的财产Controller作为Controller::registry->data['response']->setOutput().所以不应该这样说:

$this->registry->data['response']->setOutput();
Run Code Online (Sandbox Code Playgroud)

而不是$ this-> response-> setOutput();

我也给了一个Controller课程片段,所以你可以有想法.

abstract class Controller {
    protected $registry;    
    //Other Properties
    public function __construct($registry) {
        $this->registry = $registry;
    }
    public function __get($key) {
        //get() returns registry->data[$key];
        return $this->registry->get($key);
    }
    public function __set($key, $value) {
        $this->registry->set($key, $value);
    }
    //Other methods
} …
Run Code Online (Sandbox Code Playgroud)

php magic-methods opencart

5
推荐指数
1
解决办法
1675
查看次数

在htaccess规则中使www可选

我跟随.htaccess将域指向子文件夹.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} site.com
RewriteCond %{REQUEST_URI} !folder_site/
RewriteRule ^(.*)$ folder_site/$1 [L]
Run Code Online (Sandbox Code Playgroud)

如何更改RewriteCond %{HTTP_HOST} site.com为还包括www可选匹配项.

.htaccess

1
推荐指数
1
解决办法
1230
查看次数

标签 统计

.htaccess ×1

magic-methods ×1

opencart ×1

php ×1