无法在PrestaShop中安装自定义模块。

huangapple go评论73阅读模式
英文:

Cannot install custom module in prestashop

问题

我是新手Prestashop模块开发者。我正在尝试构建我的第一个Prestashop模块[参考:这是我的代码。我按照教程https://devdocs.prestashop-project.org/8/modules/creation/tutorial/中的说明做了一切,但仍然遇到问题:“无法安装模块My。模块无效,无法加载。” PHP环境:7.4,Prestahop:8.1.0

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

class MyModule extends Module
{
    public function __construct()
    {
        $this->name = 'mymodule';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'Firstname Lastname';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = [
            'min' => '1.7.0.0',
            'max' => '8.99.99',
        ];
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('My module');
        $this->description = $this->l('Description of my module.');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

        if (!Configuration::get('MYMODULE_NAME')) {
            $this->warning = $this->l('No name provided');
        }
    }
    public function install()
    {
        if (Shop::isFeatureActive()) {
            Shop::setContext(Shop::CONTEXT_ALL);
        }

        return (
            parent::install()
            && Configuration::updateValue('MYMODULE_NAME', 'my module')
        );
    }
    public function uninstall()
    {
        return (
            parent::uninstall()
            && Configuration::deleteByName('MYMODULE_NAME')
        );
    }
}

我按照教程中的说明做了一切。我本来希望它会安装我的自定义模块到Prestashop。

英文:

I am new in Prestashop module development. I am trying to build amy first prestashop module[ref: Here is my code.I did everything as in that tutorial writes https://devdocs.prestashop-project.org/8/modules/creation/tutorial/ and still have a problem 'Cannot Install module My. The module is invalid and cannot be loaded.' Enviroment PHP:7.4, Prestahop : 8.1.0

&lt;?php
if (!defined(&#39;_PS_VERSION_&#39;)) {
    exit;
}

class MyModule extends Module
{
    public function __construct()
    {
        $this-&gt;name = &#39;mymodule&#39;;
        $this-&gt;tab = &#39;front_office_features&#39;;
        $this-&gt;version = &#39;1.0.0&#39;;
        $this-&gt;author = &#39;Firstname Lastname&#39;;
        $this-&gt;need_instance = 0;
        $this-&gt;ps_versions_compliancy = [
            &#39;min&#39; =&gt; &#39;1.7.0.0&#39;,
            &#39;max&#39; =&gt; &#39;8.99.99&#39;,
        ];
        $this-&gt;bootstrap = true;

        parent::__construct();

        $this-&gt;displayName = $this-&gt;l(&#39;My module&#39;);
        $this-&gt;description = $this-&gt;l(&#39;Description of my module.&#39;);

        $this-&gt;confirmUninstall = $this-&gt;l(&#39;Are you sure you want to uninstall?&#39;);

        if (!Configuration::get(&#39;MYMODULE_NAME&#39;)) {
            $this-&gt;warning = $this-&gt;l(&#39;No name provided&#39;);
        }
    }
    public function install()
    {
        if (Shop::isFeatureActive()) {
            Shop::setContext(Shop::CONTEXT_ALL);
        }

        return (
            parent::install()
            &amp;&amp; Configuration::updateValue(&#39;MYMODULE_NAME&#39;, &#39;my module&#39;)
        );
    }
    public function uninstall()
    {
        return (
            parent::uninstall()
            &amp;&amp; Configuration::deleteByName(&#39;MYMODULE_NAME&#39;)
        );
    }
}

I did everything what as in tutorial writes. I did expect that it installed my custom module to prestashop.

答案1

得分: 1

我不知道是否能提供帮助,但请尝试检查您的PHP文件是否与“mymodule”在“$this->name = 'mymodule';”中相同。

英文:

I don't know if I can be of help but try to check if your php file is the same as the "mymodule" in "$this->name = 'mymodule'; "

huangapple
  • 本文由 发表于 2023年7月23日 19:03:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76747891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定