2017-03-02 11 views
0

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の中のモジュールの開発でデバッグ方法を教えてくださいです。

答えて

0

adminフォルダ内のindex.phpで管理者(バックオフィス)が使用されているため、ファイルを作成する場所を指定しないと、管理フォルダ内に作成されます。 モジュールフォルダにファイルを作成するには、次のようなものを使用します。

$file = _PS_MODULE_DIR_ . $this->name .'/newfile.txt'; 
関連する問題