0

我是 Prestashop 模块开发的新手。我试图在安装模块时创建一个 txt 文件,但它既没有创建文件也没有显示错误。

这是我的代码

<?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 = array('min' => '1.6', 'max' => _PS_VERSION_); 
    $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 (!parent::install())
        return false;

        // create file at time of installation
        $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
        $txt = "hello world\n";
        fwrite($myfile, $txt);
        fclose($myfile);

        return true;
    }

    public function uninstall()
    {
      if (!parent::uninstall())
        return false;

      // delete created file
      delete("newfile.txt");
      return true;
    }

}

请告诉我如何在 Prestashop 的模块开发中进行调试。

4

1 回答 1

0

由于 Admin(后台)是通过 admin 文件夹中的 index.php 使用的,因此如果您不指定创建文件的文件夹,它将在那里创建(在 admin 文件夹中)。要在模块文件夹中创建文件,请使用以下内容:

$file = _PS_MODULE_DIR_ . $this->name .'/newfile.txt';
于 2017-03-02T07:57:12.043 回答