0

我正在创建一个后台(bo)模块来查看bo中的休眠用户,我创建了模块并且模块正在正确安装并且菜单已创建并且我能够正确卸载它,但是当我单击菜单“休眠用户”时我在functions.php中遇到错误,我没有接触过这个页面。

致命错误:在第 279 行调用 D:\xampp\htdocs\raffleV1.1\oknr9hexztcseff5\functions.php 中未定义的方法 DormantUsers::viewAccess()

这是我的模块的链接 https://www.dropbox.com/s/xlg6623jwyx4nnp/dormantusers.zip?dl=0 提取并尝试检查为什么会发生此错误。我正在尝试解决这个问题超过 3 个小时,找不到任何提示,

我所做的是以下我在模块文件夹中创建了 dormantusers 文件夹并创建了 dormantusers.php,下面是该页面中的代码。

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

class DormantUsers extends Module
{
public function __construct()
{
    $this->name = 'dormantusers';
    $this->tab = 'others';
    $this->version = '1.0.0';
    $this->author = 'KITS';
    $this->need_instance = 0;

    /**
     * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
     */
    $this->bootstrap = true;

    parent::__construct();
    $this->displayName = $this->l('DormantUsers');
    $this->description = $this->l('Allow your Back Office to View Dormant Users ');
    $this->confirmUninstall = $this->l('You want to Uninstall DormantUsers ?.');
    $this->_tabsArray = array(
    'DormantUsers' => 'Dormant Users',        
    );
}

/**
 * Don't forget to create update methods if needed:
 * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
 */
public function install()
{
    return parent::install() && $this->_installTabs();
}

private function _installTabs()
{
    $parentTab = new Tab();
    foreach (Language::getLanguages() as $language) $parentTab->name[$language['id_lang']] = 'Dormant Users';
    $parentTab->class_name = 'DormantUsers';
    $parentTab->module = $this->name;
    $parentTab->id_parent = 0;
    if (!$parentTab->save()) return false;
    else {
        $idTab = $parentTab->id;
        //$idEn = Language::getIdByIso('en');
        foreach ($this->_tabsArray as $tabKey => $name) {
            $childTab = new Tab();

            foreach (Language::getLanguages() as $language) $childTab->name[$language['id_lang']] = $name;

            $childTab->class_name = $tabKey;
            $childTab->module = $this->name;
            $childTab->id_parent = $idTab;

            if (!$childTab->save()) return false;
        }
    }
    return true;
}



public function uninstall()
{

    $this->_uninstallTabs();
    return parent::uninstall();
}


private function _uninstallTabs()
{
    foreach ($this->_tabsArray as $tabKey => $name) {
        $idTab = Tab::getIdFromClassName($tabKey);
        if ($idTab != 0) {
            $tab = new Tab($idTab);
            $tab->delete();
        }
    }

    $idTab = Tab::getIdFromClassName('DormantUsers');
    if ($idTab != 0) {
        $tab = new Tab($idTab);
        $tab->delete();
    }
    return true;
}




/**
 * Add the CSS & JavaScript files you want to be loaded in the BO.
 */
public function hookBackOfficeHeader()
{
    if (Tools::getValue('module_name') == $this->name) {
    }
}
 }

在控制器文件夹 controllers/admin/DormantUsersController.php 中有以下代码。

 <?php
 require_once(_PS_MODULE_DIR_.'dormantusers/dormantusers.php');
 require_once(_PS_MODULE_DIR_.'dormantusers/classes/DormantUsers.php');
 class DormantUsersController extends ModuleAdminController
 {
    public $module;
    public $html;
    public $tabName = 'renderForm';

public function __construct()
{
    $this->tab = 'dormantusers';
    $this->module = new dormantusers();        
    $this->addRowAction('view');
    $this->explicitSelect = false;
    $this->context = Context::getContext();
    $this->id_lang = $this->context->language->id;
    $this->lang = false;
    $this->ajax = 1;
    $this->path = _MODULE_DIR_.'dormantusers';
    $this->default_form_language = $this->context->language->id;

    $this->table = 'customers';
    $this->className = 'DormantUsers';
    $this->identifier = 'id_customer';
    $this->allow_export = true;
    $this->_select = '
    firstname,
    lastname,
    email,
    nationality,
    passport_no,
    date_add
    ';

    $this->name = 'DormantUsers';
    $this->bootstrap = true;

    $this->initList();
    parent::__construct();
}


 private function initList()
  {
   $this->fields_list = array(
    'firstname' => array(
    'title' => $this->l('First Name'),
    'width' => 140,
    'type' => 'text',
    ),
    'lastname' => array(
    'title' => $this->l('Last Name'),
    'width' => 140,
    'type' => 'text',
    ),
    'email' => array(
    'title' => $this->l('Email'),
    'width' => 140,
    'type' => 'text',       
    ),
    'nationality' => array(
    'title' => $this->l('Nationality'),
    'width' => 140,
    'type' => 'text',       
    ),
    'date_add' => array(
    'title' => $this->l('date add'),
    'width' => 140,
    'type' => 'text',
    ),
    'passport_no' => array(
    'title' => $this->l('passport_no'),
    'width' => 140,
    'type' => 'text',
    ),
);
$helper = new HelperList();     
$helper->shopLinkType = '';     
$helper->simple_header = true;

// Actions to be displayed in the "Actions" column
$helper->actions = array('view');

$helper->identifier = 'id_customer';
$helper->show_toolbar = true;
$helper->title = 'HelperList';

$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
   return $helper;
}
public function initPageHeaderToolbar()
{
    $this->page_header_toolbar_title = $this->l('Dormant Users List ');
    parent::initPageHeaderToolbar();
}

public function initToolbar()
{
    parent::initToolbar();

    $this->context->smarty->assign('toolbar_scroll', 1);
    $this->context->smarty->assign('show_toolbar', 1);
    $this->context->smarty->assign('toolbar_btn', $this->toolbar_btn);

}   

public function postProcess()
{   
    parent::postProcess();

 }  

  } 
4

1 回答 1

0

您必须在 DormantUsersController 类中定义函数 viewAccess。试试这个代码

public function viewAccess($disable = false)
{
    if (version_compare(_PS_VERSION_, '1.5.1.0', '<='))
        return true;
    return parent::viewAccess($disable);

}
于 2016-05-04T08:44:34.077 回答