Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 模块lang在Prestashop 1.7.6中不工作_Php_Prestashop_Prestashop 1.7_Prestashop Modules - Fatal编程技术网

Php 模块lang在Prestashop 1.7.6中不工作

Php 模块lang在Prestashop 1.7.6中不工作,php,prestashop,prestashop-1.7,prestashop-modules,Php,Prestashop,Prestashop 1.7,Prestashop Modules,只是尝试创建一个带有翻译的新的简单模块,但保存过程不起作用。表“ps_myoptions_lang”正在使用每个lang_id中的字段id_myoptions=0进行更新,“ps_myoptions”中未保存任何内容 模块/myoptions/controllers/admin/adminoptioncontroller.php <?php require_once(dirname(__FILE__) . './../../classes/Option.php'); class A

只是尝试创建一个带有翻译的新的简单模块,但保存过程不起作用。表“ps_myoptions_lang”正在使用每个lang_id中的字段
id_myoptions=0
进行更新,“ps_myoptions”中未保存任何内容

模块/myoptions/controllers/admin/adminoptioncontroller.php

<?php


require_once(dirname(__FILE__) . './../../classes/Option.php');

class AdminOptionsController extends AdminController
{
    public function __construct(){
        parent::__construct();
        $this->bootstrap = true; // use Bootstrap CSS
        $this->table = 'myoptions'; // SQL table name, will be prefixed with _DB_PREFIX_
        $this->lang = true;
        $this->identifier = 'id_myoptions'; // SQL column to be used as primary key



        $this->className = 'Option'; // PHP class name
        $this->allow_export = true; // allow export in CSV, XLS..


        $this->_defaultOrderBy = 'a.name'; // the table alias is always `a`
        $this->_defaultOrderWay = 'DESC';
        $this->fields_list = [
            'id_myoptions' => ['title' => 'ID','class' => 'fixed-width-xs'],
            'name' => ['title' => 'Name'],
        ];

        $this->addRowAction('edit');
        $this->addRowAction('details');

        $this->fields_form = [
            'legend' => [
                'title' => 'Pasta',
                'icon' => 'icon-list-ul'
            ],
            'input' => [
                ['name'=>'name','type'=>'text', 'lang' => true, 'label'=>'Name','required'=>true],
            ],
            'submit' => [
                'title' => $this->trans('Save', [], 'Admin.Actions'),
            ]
        ];
    }
}

<?php


class Option extends ObjectModel
{
    public $id;
    public $name;

    public static $definition = [
        'table' => 'myoptions',
        'primary' => 'id_myoptions',
        'multilang' => true,
        'fields' => [
            'name' =>  ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isAnything', 'required'=>true],
        ],
    ];
}

if (!defined('_PS_VERSION_')) {
    exit;
}

class Myoptions extends Module
{
    protected $config_form = false;


    public function __construct()
    {
        $this->name = 'myoptions';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'abc';
        $this->need_instance = 1;

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

        parent::__construct();

        $this->displayName = $this->l('My Options');
        $this->description = $this->l('Add additional options');

        $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
    }

    /**
     * Don't forget to create update methods if needed:
     * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
     */
    public function install()
    {
        Configuration::updateValue('MYOPTIONS_LIVE_MODE', false);

        include(dirname(__FILE__).'/sql/install.php');

        return parent::install() &&
            $this->registerHook('header') &&
            $this->registerHook('backOfficeHeader') &&
            $this->installTabs();
    }

    public function uninstall()
    {
        Configuration::deleteByName('MYOPTIONS_LIVE_MODE');

        include(dirname(__FILE__).'/sql/uninstall.php');

        return parent::uninstall();
    }

    public function enable($force_all = false)
    {
        return parent::enable($force_all)
            && $this->installTabs()
            ;
    }

    public function disable($force_all = false)
    {
        return parent::disable($force_all)
           && $this->uninstallTabs()
            ;
    }

    /**
     * Since PS 1.7.1
     * @var array
     */
    public $tabs = array(
        array(
            'name' => array(
                'en' => 'Options', // Default value should be first
                'fr' => 'Options',
            ),
            'class_name' => 'AdminOptions',
            'visible' => true,
            'parent_class_name' => 'AdminParentThemes',
        ),

    );

    public function installTabs()
    {
        $moduleName = $this->name;

        $this->addTab('AdminOptions', 'Options', $moduleName, 'AdminTools');




        return true;
    }
public function addTab($className, $tabName, $moduleName, $parentClassName)
    {
        $tab = new Tab();
        $tab->active = 1;
        $tab->class_name = $className;
        $tab->name = array();
        foreach (Language::getLanguages(true) as $lang) {
            $tab->name[$lang['id_lang']] = $tabName;
        }

        $tab->id_parent = (int) Tab::getIdFromClassName($parentClassName);

        $tab->module = $moduleName;

        $tab->add();

        return $tab;
    }
}
有什么我做错了吗

谢谢你的回答

Prestashop 1.7.6
PHP 7.2.25

我想我发现了问题:

    $sqlCreate = "CREATE TABLE `" . _DB_PREFIX_ . "myoptions` (
                `id_myoptions` int(11) unsigned NOT NULL AUTO_INCREMENT,
                `name` varchar(255) DEFAULT NULL,
                PRIMARY KEY (`id_myoptions`)
                ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";

$sqlCreateLang = "CREATE TABLE `" .  _DB_PREFIX_ . "myoptions_lang` (
              `id_myoptions` int(11) unsigned NOT NULL AUTO_INCREMENT,
              `id_lang` int(11) NOT NULL,
              `name` varchar(255) DEFAULT NULL,
              PRIMARY KEY (`id_myoptions`,`id_lang`)
            ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";

Db::getInstance()->execute($sqlCreate) && Db::getInstance()->execute($sqlCreateLang);

我在两个表中都有相同的字段
名称
。然后我只在Lang表中使用它,现在似乎可以使用了。

您必须从ModuleAdminController扩展管理控制器。一切似乎都很好。发布您的SQL文件