问题描述
在prestashop中生成模块控制器的链接的确切方法是什么?
What's the exact way to generate a link to a module controller in prestashop? Also, how should really be named the controller's class and how the url params should mirror?
推荐答案
你将使用一个实例的链接类。通常你不必创建一个,只需使用上下文 - >链接(例如形成一个控制器$ this->上下文链接)。方法是getModuleLink(),因此:
You will use an instance of the Link class. Generally you don't have to create one, just use context->link (ex. form a controller $this->context-link). The method is getModuleLink(), so:
$this->context->link->getModuleLink('module_folder_name','controller_name',array_of_params);
注意命名:
- $ b
控制器必须在正确的路径,例如module / controllers / front / controller.php
The controller must be in the right path, so for example module/controllers/front/controller.php
文件名是操作,小写。类名称为ModuleFolder + Action +ModuleFrontController
The file name is the action, lowercase. The class name is ModuleFolder+Action+"ModuleFrontController"
因此,例如:
module dir: orderattachment
module dir: orderattachment
controller: orderattachment / controllers / front / php
controller: orderattachment/controllers/front/pdf.php
控制器类:
class OrderAttachmentPdfModuleFrontController extends ModuleFrontController
链接:
$this->context->getModuleLink('orderattachments', 'pdf', [params..]);
这篇关于如何生成一个链接到模块控制器在prestashop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!