问题描述
我正在开发一个带有控制器的模块,用于读取 id_cart 并执行一些操作.但是我不能调用Controller,它总是返回404错误.
I am developing a module with a controller which is intended to read id_cart and do some actions. But I cannot invoke Controller, it always returns 404 error.
模块:
<?php
if (!defined('_PS_VERSION_'))
exit;
class CartPortkey extends Module
{
public function __construct()
{
$this->name = 'cartportkey';
$this->tab = 'checkout';
$this->version = '1.0.0';
$this->author = 'Me and nobody else';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('My Module Name');
$this->description = $this->l('My Module Description.');
$this->confirmUninstall = $this->l('Estás seguro de desinstalar?');
}
}
控制器
<?php
if (!defined('_PS_VERSION_'))
exit;
class CartPortkeyFrontController extends ModuleFrontController {
public function init(){
parent::init();
$id_cart = (int)Tools::getValue('id_cart');
$this->context->cookie->id_cart = $id_cart;
$link_order = $this->context->link->getPageLink('order');
Tools::redirect($link_order);
}
public function initContent() {
parent::initContent();
}
}
?>
我正在尝试这个网址:http://localhost/shop/myshop1/index.php?fc=module&module=cartportkey&controller=cartportkeyfrontcontroller&id_cart=2
我必须指定我已启用多商店,其中 shop
是主要商店,myshop1
是 3 个商店之一.
I have to specify that I have enabled multistore where shop
is the main and myshop1
is one of the 3 shops.
文件夹结构:
+ cartportkey
-- +controllers
-- -- +front
-- -- -- CartPortKeyController.php
-- cartportkey.php
我已确保该模块已安装并在所有商店中处于活动状态.
I have ensured that the module is installed and active in all the stores.
推荐答案
您的控制器命名约定有误.
You have the controller naming convention wrong.
您需要如下声明前端控制器类.
You need to declare the front controller class as follows.
ModuleNameControllerFileNameModuleFrontController extends ModuleFrontController
所以目前你的控制器类应该声明为
So currently your controller class should be declared as
CartPortKeyCartPoortKeyControllerModuleFrontController extends ModuleFrontController
然后使用以下网址加载控制器
Then load the controller with the following url
http://localhost/shop/myshop1/index.php?fc=module&module=cartportkey&controller=cartpoortkeycontroller&id_cart=2
这篇关于带控制器的 Prestashop 模块抛出 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!