Php Prestashop自定义模块可拖动排序/订单

Php Prestashop自定义模块可拖动排序/订单,php,prestashop,prestashop-1.6,Php,Prestashop,Prestashop 1.6,请告诉我为什么我有一个“块实现声明::updatePosition($way,$position,$id)应该与ModuleCore::updatePosition($id\u hook,$way,$position=NULL)兼容” 我在module.php中有这段代码 <?php if (!defined('_PS_VERSION_')) exit; class BlockRealization extends Module { protected $_html = ''; pu

请告诉我为什么我有一个“块实现声明::updatePosition($way,$position,$id)应该与ModuleCore::updatePosition($id\u hook,$way,$position=NULL)兼容”

我在module.php中有这段代码

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

class BlockRealization extends Module {

protected $_html = '';

public function __construct() {

$this->name = 'blockrealization';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'XXX';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
$this->bootstrap = true;

parent::__construct();

$this->displayName = $this->l('Module realization');
$this->description = $this->l('Display realization on homepage.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); 
}

public function install() {
if (!parent::install() ||
    !$this->registerHook('displayHeader') ||
    !$this->registerHook('home') ||
    !$this->createTables()
)
    return false;
return true;
}

public function uninstall() {
if (!parent::uninstall() ||
    !$this->removeTable())
    return false;
return true;
}

protected function createTables() {

/* Realization */
$res = (bool)Db::getInstance()->execute('
    CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'realization` (
        `id_realization_slides` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `image_realization` varchar(255) NOT NULL,
        `position` int(10) unsigned NOT NULL,
        PRIMARY KEY (`id_realization_slides`, `image_realization`)
    ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');

return $res;
}

protected function removeTable() {
if (!Db::getInstance()->Execute('DROP TABLE `'. _DB_PREFIX_ . 'realization`'))
    return false;
return true;
}

public function getContent() {

$output = null;

if (Tools::isSubmit('submit'.$this->name)) {
    $errors = '';

    if ($_FILES) {

        $helper = new HelperImageUploader('realization_img');
        $files = $helper->process();

        if ($files) {

            foreach ($files as $file) {

                if (isset($file['save_path'])) {
                    if (!ImageManager::checkImageMemoryLimit($file['save_path']))
                    $errors = Tools::displayError('Limit');

                    if (!$errors) {
                        if (!ImageManager::resize($file['save_path'], dirname(__FILE__) . '/img/' . $file['name']))
                            $errors = Tools::displayError('error');
                        else {

                            $previous_file = Configuration::get('realization_img');
                            $file_path = dirname(__FILE__) . '/img/' . $previous_file;

                            if (file_exists($file_path))
                                unlink($file_path);


                            $realization['image_realization'] = $file['name'];
                            $realization['position'] = count($this->getAll());
                            if (!Db::getInstance()->insert('realization', $realization))
                                $errors = Tools::displayError('error');
                        }
                    }

                    unlink($file['save_path']);
                }
            }
        }
    }

    if ($errors) 
        $output .= $this->displayError($errors);
    else 

        $output .= $this->displayConfirmation($this->l('Settings updated'));
}

$output .= $this->generateList();
$output .= $this->displayForm();

return $output;
}

public function displayForm() {

 // Init Fields form array
 $fields_form[0]['form'] = array(
    'legend' => array(
        'title' => $this->l('Add the realization'),
    ),
    'input' => array(
        array(
            'type' => 'file',                              
            'label' => $this->l('Image:'),
            'name' => 'realization_img',
            'hint' => $this->l('Upload image for contact:'),
        )
    ),
    'submit' => array(
        'title' => $this->l('Save'),
        'class' => 'btn btn-default pull-right'
    )
);

$helper = new HelperForm();

// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;        // false -> remove toolbar
$helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
    'save' =>
    array(
        'desc' => $this->l('Save'),
        'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
        '&token='.Tools::getAdminTokenLite('AdminModules'),
    ),
    'back' => array(
        'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
        'desc' => $this->l('Back to list')
    )
);

// Load current value
$helper->tpl_vars = array(
    'fields_value' => array(
        'realization_img' => Configuration::get('realization_img')
    )
);

return $helper->generateForm($fields_form);
}

public function generateList() {
$content = $this->getAll();

$fields_list = array(
    'id_realization_slides' => array(
        'title' => 'ID',
        'align' => 'center',
        'class' => 'fixed-width-xs',
    ),
    'image_realization' => array(
        'title' => $this->l('Image'),
        'orderby' => false,
        'search' => false
    ),
    'position' => array(
        'title' => $this->l('Position'),
        'position' => 'position' ,
        'orderby' => false,
        'search' => false
    ),
);

$helper = new HelperList();
$helper->shopLinkType = '';
$helper->actions = array('edit', 'delete');
$helper->module = $this;
$helper->listTotal = count($content);
$helper->identifier = 'id_realization_slides';
$helper->title = $this->l('Realizations');
$helper->table = $this->name;
$helper->imageType = 'jpg';
$helper->orderBy = 'position';
$helper->orderWay = 'asc';
$helper->position_identifier = 'id_realization_slides';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

return $helper->generateList($content, $fields_list);
}

public function getAll() {
return Db::getInstance()->ExecuteS('
    SELECT *
    FROM '._DB_PREFIX_.'realization
');
}

public function ajaxProcessUpdatePositions()
{
$way = (int)Tools::getValue('way');
$id_quicklinks = (int)Tools::getValue('id');
$positions = Tools::getValue('realization_slides');

if (is_array($positions))
    foreach ($positions as $position => $value)
    {
        $pos = explode('_', $value);

        if (isset($pos[2]) && (int)$pos[2] === $id_velcroquicklinks)
        {
                if (isset($position) && $this->updatePosition($way, $position, $id_quicklinks))
                    echo 'ok position '.(int)$position.' for id '.(int)$pos[1].'\r\n';
                else
                    echo '{"hasError" : true, "errors" : "Can not update id '.(int)$id_quicklinks.' to position '.(int)$position.' "}';

            break;
        }
    }

 }

public function updatePosition($way, $position, $id)
{

if (!$res = Db::getInstance()->executeS('
    SELECT `id_realization_slides`, `position`
    FROM `'._DB_PREFIX_.'realization`
    ORDER BY `position` ASC'
))
    return false;

foreach ($res as $quicklinks)
    if ((int)$quicklinks['id_realization_slides'] == (int)$id)
        $moved_quicklinks = $quicklinks;

if (!isset($moved_quicklinks) || !isset($position))
    return false;

return (Db::getInstance()->execute('
    UPDATE `'._DB_PREFIX_.'realization`
    SET `position`= `position` '.($way ? '- 1' : '+ 1').'
    WHERE `position`
    '.($way
        ? '> '.(int)$moved_quicklinks['position'].' AND `position` <= '.(int)$position
        : '< '.(int)$moved_quicklinks['position'].' AND `position` >= '.(int)$position.'
    '))
&& Db::getInstance()->execute('
    UPDATE `'._DB_PREFIX_.'realization`
    SET `position` = '.(int)$position.'
    WHERE `id_realization_slides` = '.(int)$moved_quicklinks['id_quicklinks']));
 }

 public function hookHome($params) {

return $this->display(__FILE__, "views/templates/hook/realization.tpl");
}
这里也有类似的问题 ?

在module.php中的我的代码下

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

class BlockRealization extends Module {

protected $_html = '';

public function __construct() {

$this->name = 'blockrealization';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'XXX';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
$this->bootstrap = true;

parent::__construct();

$this->displayName = $this->l('Module realization');
$this->description = $this->l('Display realization on homepage.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); 
}

public function install() {
if (!parent::install() ||
    !$this->registerHook('displayHeader') ||
    !$this->registerHook('home') ||
    !$this->createTables()
)
    return false;
return true;
}

public function uninstall() {
if (!parent::uninstall() ||
    !$this->removeTable())
    return false;
return true;
}

protected function createTables() {

/* Realization */
$res = (bool)Db::getInstance()->execute('
    CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'realization` (
        `id_realization_slides` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `image_realization` varchar(255) NOT NULL,
        `position` int(10) unsigned NOT NULL,
        PRIMARY KEY (`id_realization_slides`, `image_realization`)
    ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');

return $res;
}

protected function removeTable() {
if (!Db::getInstance()->Execute('DROP TABLE `'. _DB_PREFIX_ . 'realization`'))
    return false;
return true;
}

public function getContent() {

$output = null;

if (Tools::isSubmit('submit'.$this->name)) {
    $errors = '';

    if ($_FILES) {

        $helper = new HelperImageUploader('realization_img');
        $files = $helper->process();

        if ($files) {

            foreach ($files as $file) {

                if (isset($file['save_path'])) {
                    if (!ImageManager::checkImageMemoryLimit($file['save_path']))
                    $errors = Tools::displayError('Limit');

                    if (!$errors) {
                        if (!ImageManager::resize($file['save_path'], dirname(__FILE__) . '/img/' . $file['name']))
                            $errors = Tools::displayError('error');
                        else {

                            $previous_file = Configuration::get('realization_img');
                            $file_path = dirname(__FILE__) . '/img/' . $previous_file;

                            if (file_exists($file_path))
                                unlink($file_path);


                            $realization['image_realization'] = $file['name'];
                            $realization['position'] = count($this->getAll());
                            if (!Db::getInstance()->insert('realization', $realization))
                                $errors = Tools::displayError('error');
                        }
                    }

                    unlink($file['save_path']);
                }
            }
        }
    }

    if ($errors) 
        $output .= $this->displayError($errors);
    else 

        $output .= $this->displayConfirmation($this->l('Settings updated'));
}

$output .= $this->generateList();
$output .= $this->displayForm();

return $output;
}

public function displayForm() {

 // Init Fields form array
 $fields_form[0]['form'] = array(
    'legend' => array(
        'title' => $this->l('Add the realization'),
    ),
    'input' => array(
        array(
            'type' => 'file',                              
            'label' => $this->l('Image:'),
            'name' => 'realization_img',
            'hint' => $this->l('Upload image for contact:'),
        )
    ),
    'submit' => array(
        'title' => $this->l('Save'),
        'class' => 'btn btn-default pull-right'
    )
);

$helper = new HelperForm();

// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;        // false -> remove toolbar
$helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
    'save' =>
    array(
        'desc' => $this->l('Save'),
        'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
        '&token='.Tools::getAdminTokenLite('AdminModules'),
    ),
    'back' => array(
        'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
        'desc' => $this->l('Back to list')
    )
);

// Load current value
$helper->tpl_vars = array(
    'fields_value' => array(
        'realization_img' => Configuration::get('realization_img')
    )
);

return $helper->generateForm($fields_form);
}

public function generateList() {
$content = $this->getAll();

$fields_list = array(
    'id_realization_slides' => array(
        'title' => 'ID',
        'align' => 'center',
        'class' => 'fixed-width-xs',
    ),
    'image_realization' => array(
        'title' => $this->l('Image'),
        'orderby' => false,
        'search' => false
    ),
    'position' => array(
        'title' => $this->l('Position'),
        'position' => 'position' ,
        'orderby' => false,
        'search' => false
    ),
);

$helper = new HelperList();
$helper->shopLinkType = '';
$helper->actions = array('edit', 'delete');
$helper->module = $this;
$helper->listTotal = count($content);
$helper->identifier = 'id_realization_slides';
$helper->title = $this->l('Realizations');
$helper->table = $this->name;
$helper->imageType = 'jpg';
$helper->orderBy = 'position';
$helper->orderWay = 'asc';
$helper->position_identifier = 'id_realization_slides';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

return $helper->generateList($content, $fields_list);
}

public function getAll() {
return Db::getInstance()->ExecuteS('
    SELECT *
    FROM '._DB_PREFIX_.'realization
');
}

public function ajaxProcessUpdatePositions()
{
$way = (int)Tools::getValue('way');
$id_quicklinks = (int)Tools::getValue('id');
$positions = Tools::getValue('realization_slides');

if (is_array($positions))
    foreach ($positions as $position => $value)
    {
        $pos = explode('_', $value);

        if (isset($pos[2]) && (int)$pos[2] === $id_velcroquicklinks)
        {
                if (isset($position) && $this->updatePosition($way, $position, $id_quicklinks))
                    echo 'ok position '.(int)$position.' for id '.(int)$pos[1].'\r\n';
                else
                    echo '{"hasError" : true, "errors" : "Can not update id '.(int)$id_quicklinks.' to position '.(int)$position.' "}';

            break;
        }
    }

 }

public function updatePosition($way, $position, $id)
{

if (!$res = Db::getInstance()->executeS('
    SELECT `id_realization_slides`, `position`
    FROM `'._DB_PREFIX_.'realization`
    ORDER BY `position` ASC'
))
    return false;

foreach ($res as $quicklinks)
    if ((int)$quicklinks['id_realization_slides'] == (int)$id)
        $moved_quicklinks = $quicklinks;

if (!isset($moved_quicklinks) || !isset($position))
    return false;

return (Db::getInstance()->execute('
    UPDATE `'._DB_PREFIX_.'realization`
    SET `position`= `position` '.($way ? '- 1' : '+ 1').'
    WHERE `position`
    '.($way
        ? '> '.(int)$moved_quicklinks['position'].' AND `position` <= '.(int)$position
        : '< '.(int)$moved_quicklinks['position'].' AND `position` >= '.(int)$position.'
    '))
&& Db::getInstance()->execute('
    UPDATE `'._DB_PREFIX_.'realization`
    SET `position` = '.(int)$position.'
    WHERE `id_realization_slides` = '.(int)$moved_quicklinks['id_quicklinks']));
 }

 public function hookHome($params) {

return $this->display(__FILE__, "views/templates/hook/realization.tpl");
}

因为您扩展了类模块,并且它已经有了与您基本重写的相同的方法。在PHP7+中,如果要重写或扩展方法,则必须声明相同的参数(即使它们在父类方法中具有默认值)和相同的访问级别。因此,您只需要遵循规则并使用相同的声明,或者如果不需要重写/扩展父类1(看起来是这样的),您可以重命名您的方法。

因为您扩展了类模块,并且它已经具有基本上重写的相同方法。在PHP7+中,如果要重写或扩展方法,则必须声明相同的参数(即使它们在父类方法中具有默认值)和相同的访问级别。因此,您只需要遵循规则并使用相同的声明,或者如果不需要重写/扩展父类1(看起来是这样的话),您可以重命名您的方法。

您可以提供代码或示例吗?在哪里可以找到该方法的外观?具有相同数量的参数和默认值以及相同的可见性范围非常重要。例如,parentClass::customMethod($1,$2,$3=false)和childClass::customMethod($1,$2,$3)您将得到一个错误,因为参数不同,或者如果您将错过其中一个,等等。声明必须相同,如果parentClass::customMethod为public/protected/private,则childClass::customMethod也必须具有相同的声明。所以,childClass::customMethod($1,$2,$3=false)必须像这里一样,您可以提供代码或示例吗?在哪里可以找到该方法的外观?具有相同数量的参数和默认值以及相同的可见性范围非常重要。例如,parentClass::customMethod($1,$2,$3=false)和childClass::customMethod($1,$2,$3)您将得到一个错误,因为参数不同,或者如果您将错过其中一个,等等。声明必须相同,如果parentClass::customMethod为public/protected/private,则childClass::customMethod也必须具有相同的声明。因此,childClass::customMethod($1,$2,$3=false)必须与这里类似