Php 将类添加到Opencart操作文件
实际上,我正在尝试将类(Controllerjournal3flashsale)添加到action.php中,我想要这个类,因为我使用的是来自journal 3主题的动态块,当我在布局下添加块时,它不起作用,它只显示动态块内容,而不是同时显示页面的其余内容。我尝试了很多方法,但都出现了错误: 错误是:Php 将类添加到Opencart操作文件,php,opencart,journal,Php,Opencart,Journal,实际上,我正在尝试将类(Controllerjournal3flashsale)添加到action.php中,我想要这个类,因为我使用的是来自journal 3主题的动态块,当我在布局下添加块时,它不起作用,它只显示动态块内容,而不是同时显示页面的其余内容。我尝试了很多方法,但都出现了错误: 错误是: Fatal error: Uncaught Error: Class 'Controllerjournal3flashsale' not found in /home/mywebsite/stor
Fatal error: Uncaught Error: Class 'Controllerjournal3flashsale' not found in /home/mywebsite/storage_aelive/modification/system/engine/action.php:71 Stack trace: #0 /home/mywebsite/storage_aelive/modification/system/engine/loader.php(27): Action->execute(Object(Registry), Array) #1 /home/mywebsite/public_html/catalog/controller/journal3/blocks.php(133): Loader->controller('journal3/flash_...', Array) #2 /home/mywebsite/public_html/live/library/journal3/opencart/modulecontroller.php(149): ControllerJournal3Blocks->beforeRender() #3 /home/mywebsite/public_html/catalog/controller/journal3/blocks.php(18): Journal3\Opencart\ModuleController->index(Array) #4 /home/mywebsite/storage_aelive/modification/system/engine/action.php(79): ControllerJournal3Blocks->index(Array) #5
/home/mywebsite/storage_aelive/modification/system/engine/loader.php(27): Action->execute(Object(Registry), Array) #6
/home/mywebsite/public_html/live/library/journal3/opencart/controller.php(112): Loader->controller('journal3/blocks', Array) #7 /home/clearan in /home/mywebsite/storage_aelive/modification/system/engine/action.php on line 71
action.php文件代码如下:
class Action {
private $id;
private $route;
private $method = 'index';
/**
* Constructor
*
* @param string $route
*/
public function __construct($route) {
$this->id = $route;
$parts = explode('/', preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route));
// Break apart the route
while ($parts) {
$file = DIR_APPLICATION . 'controller/' . implode('/', $parts) . '.php';
if (is_file($file)) {
$this->route = implode('/', $parts);
break;
} else {
$this->method = array_pop($parts);
}
}
}
/**
*
*
* @return string
*
*/
public function getId() {
return $this->id;
}
/**
*
*
* @param object $registry
* @param array $args
*/
public function execute($registry, array $args = array()) {
// Stop any magical methods being called
if (substr($this->method, 0, 2) == '__') {
return new \Exception('Error: Calls to magic methods are not allowed!');
}
$file = DIR_APPLICATION . 'controller/' . $this->route . '.php';
$class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $this->route);
// Initialize the class
if (is_file($file)) {
include_once(modification($file));
$controller = new $class($registry);
} else {
return new \Exception('Error: Could not call ' . $this->route . '/' . $this->method . '!');
}
$reflection = new ReflectionClass($class);
if ($reflection->hasMethod($this->method) && $reflection->getMethod($this->method)->getNumberOfRequiredParameters() <= count($args)) {
return call_user_func_array(array($controller, $this->method), $args);
} else {
return new \Exception('Error: Could not call ' . $this->route . '/' . $this->method . '!');
}
}
}
集体诉讼{
私人$id;
私人路线;;
private$method='index';
/**
*建造师
*
*@param string$route
*/
公共功能构造($route){
$this->id=$route;
$parts=分解('/',预替换('/[^a-zA-Z0-9'/]/',''(字符串)$route));
//分道扬镳
while($parts){
$file=DIR_应用程序。'controller/'。内爆('/',$parts)。'.php';
if(is_文件($file)){
$this->route=内爆(“/”,$parts);
打破
}否则{
$this->method=array\u pop($parts);
}
}
}
/**
*
*
*@返回字符串
*
*/
公共函数getId(){
返回$this->id;
}
/**
*
*
*@param object$注册表
*@param数组$args
*/
公共函数执行($registry,array$args=array()){
//停止调用任何神奇的方法
if(substr($this->method,0,2)='\uuuuu'){
return new\Exception('错误:不允许调用魔术方法!');
}
$file=DIR_应用程序。'controller/。$this->route..php';
$class='Controller'.preg_replace('/[^a-zA-Z0-9]/',''.$this->route);
//初始化类
if(is_文件($file)){
包括一次(修改($file));
$controller=新的$class($registry);
}否则{
return new\Exception('错误:无法调用'$this->route.'/'.$this->method.!');
}
$reflection=新的ReflectionClass($class);
如果($reflection->hasMethod($this->method)和(&$reflection->getMethod($this->method)->getNumberOfRequiredParameters()方法),$args);
}否则{
return new\Exception('错误:无法调用'$this->route.'/'.$this->method.!');
}
}
}
我建议您使用《日志手册》中的控制器结构
Theme附带了一个示例,您可以在catalog/controller/journal3/blocks\u example.php中找到它
use Journal3\Opencart\Controller;
class ControllerJournal3BlocksExample extends Controller {
public function index($args) {
return 'Dynamic Content for module_id = ' . $args['module_id'];
}
}