我在哪里可以找到 prestashop 控制器以及如何扩展它们? [英] where can I find prestashop controllers and how can i extend them?
问题描述
我是 prestashop 的新手,所以如果我问一个非常简单的问题,请耐心等待.我正在创建模块,在我的任务中,我必须扩展由 javascript 中的 ajaxcart.add() 函数调用的购物车控制器.我想知道,响应这个ajax请求的控制器在哪里,我如何在我的模块中扩展这个控制器.有关于这方面的任何好的文档吗?谢谢
I am new to prestashop, so please bear with me if I am asking a very simple question. I am into creating module, and in my task I have to extend the cart controller that is being called by the ajaxcart.add() function in the javascript. I want to know, where is the controller that responds to this ajax request is located, and how can i extend this controller in my module. Are there any good documentation regarding this? thanks
推荐答案
我找到了一种在模块内扩展 prestashop 默认控制器的方法.我查看了 classes/Dispatcher.php
的内部,并在 dispatch() 方法中找到了它
I found a way to extending the prestashop default controllers inside a module.
I looked iniside the classes/Dispatcher.php
and found this inside the dispatch() method
case self::FC_MODULE :
$module_name = Validate::isModuleName(Tools::getValue('module')) ? Tools::getValue('module') : '';
$module = Module::getInstanceByName($module_name);
$controller_class = 'PageNotFoundController';
if (Validate::isLoadedObject($module) && $module->active) {
$controllers = Dispatcher::getControllers(_PS_MODULE_DIR_.$module_name.'/controllers/front/');
if (isset($controllers[strtolower($this->controller)])) {
include_once(_PS_MODULE_DIR_.$module_name.'/controllers/front/'.$this->controller.'.php');
$controller_class = $module_name.$this->controller.'ModuleFrontController';
}
}
$params_hook_action_dispatcher = array('controller_type' => self::FC_FRONT, 'controller_class' => $controller_class, 'is_module' => 1);
所以,控制器的命名约定是
So, The naming convention for the controller is
<modulename><controllername>ModuleFrontController
控制器的路径应该是
and the path to the controller should be
module/<module name>/cotrollers/front/<controllername>.php
areacalc 模块中的示例 mycart 控制器
Example mycart controller inside an areacalc module
class areacalcmycartModuleFrontController extends CartController {
areacalc 模块中 mycart 控制器的文件路径
File path to the mycart controller inside an areacalc module
/modules/areacalc/controllers/front/mycart.php
网址是
http://localhost:8080/index.php?fc=module&module=areacalc&controller=mycart
这篇关于我在哪里可以找到 prestashop 控制器以及如何扩展它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!