Prestashop Module with controller throws 404

☆樱花仙子☆ 提交于 2019-12-11 06:39:37

问题


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.

Module:

<?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?');
  }
}

Controller

<?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();
    }

}

?>

I am trying this url: http://localhost/shop/myshop1/index.php?fc=module&module=cartportkey&controller=cartportkeyfrontcontroller&id_cart=2

I have to specify that I have enabled multistore where shop is the main and myshop1 is one of the 3 shops.

Folder Structure:

+ cartportkey
-- +controllers
-- -- +front
-- -- -- CartPortKeyController.php
-- cartportkey.php

I have ensured that the module is installed and active in all the stores.


回答1:


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


来源:https://stackoverflow.com/questions/40491693/prestashop-module-with-controller-throws-404

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!