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

问题描述:

我是Prestashop模块开发中的新成员。我试图在模块安装时创建一个txt文件,但它既不创建文件也不显示错误。如何在安装时在Prestashop Module文件夹中创建文件

这里是我的代码

<?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模块的开发调试。

由于Admin(后台)通过admin文件夹中的index.php使用,如果您未指定创建文件的文件夹,它将在那里创建(在admin文件夹中)。 要创建您的模块文件夹中的文件使用类似于:

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