簡體   English   中英

Prestashop模塊控制器訪問

[英]Prestashop module controller access

我正在嘗試使用Prestashop 1.7創建新的頁面模板,並且我知道我必須為此使用模塊。

我遵循了本教程: http : //nemops.com/creating-new-pages-in-prestashop/#.WnrWa5OdVGy

不幸的是,當我想查看使用https://example.com/index.php?fc=module&module=aktest&controller=testindex創建的模塊時,我得到了404頁...

模塊(modules / aktest / aktest.php)

<?php
if (!defined('_PS_VERSION_'))
  exit;

class Aktest extends Module
{
  public function __construct()
  {
    $this->name = 'aktest';
    $this->tab = 'front_office_features';
    $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('Uninstall?');
  }
}

控制器(modules / aktest / controllers / front / testindex.php)-目前為空白

<?php
class AktestTestindexModuleFrontController extends ModuleFrontController{
    public function init(){
        parent::init();
    }
    public function initContent() {
        parent::initContent();
    }
}

這可能只是商店系統告訴您沒有任何可顯示的內容。

當在PrestaShop 1.7.5安裝上嘗試代碼(並使PS_DEV_MODE=1 )時,在控制台上出現HTTP 500錯誤以及以下PHP錯誤:

[Thu Jan 31 06:29:28.106955 2019] [:error] [pid 39] [client 127.0.0.1:41558] PHP Fatal error:  Uncaught  --> Smarty: 0():Missing '$template' parameter <-- \n  thrown in /var/www/html/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php on line 177
[31/Jan/2019:06:29:27 +0000] "GET /index.php?fc=module&module=aktest&controller=testindex HTTP/1.1" 500 403 "-" "Mozilla/5.0 Agent"

因此,如果您更改了控制器代碼

<?php
class AktestTestindexModuleFrontController extends ModuleFrontController{
    public function init(){
        parent::init();
    }

    public function initContent() {
        parent::initContent();
        $this->setTemplate('module:aktest/views/templates/front/testindex.tpl');
    }
}

並在modules/aktest/views/templates/front/testindex.tpl創建了一個最小的模板

{extends file='page.tpl'}

{block name='page_content'}
    Well hello there
{/block}

那么您的控制器應該顯示一些內容。

萬一東西總是好的不起作用, 打開調試模式Admin Panel -> Configure -> Advanced Settings -> Performance -> Debug Mode ,並檢查日志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM