如何在安装时在Prestashop Module文件夹中创建文件

时间:2017-03-02 06:20:23

标签: prestashop-1.7

我是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中进行模块开发调试。

1 个答案:

答案 0 :(得分:0)

由于admin(后台)通过admin文件夹中的index.php使用,如果您没有指定创建文件的文件夹,则会在那里创建(在admin文件夹中)。 要在模块文件夹中创建文件,请使用以下内容:

$file = _PS_MODULE_DIR_ . $this->name .'/newfile.txt';