简体   繁体   English

在Codeigniter Framework中使用php在YAML文件上写

[英]Write on YAML file using php in codeigniter Framework

I'm using YAML library with codeIgniter and I was adding data manually but now I decided I need to add it automatically and I'm asking how to add a line at the end of a .YML file? 我正在将YAML库与codeIgniter一起使用,并且正在手动添加数据,但是现在我决定需要自动添加数据,并询问如何在.YML文件的末尾添加一行?

Clarification: when I insert some data in the database in the same time I need to store some of it in the YML file ( for other use ) 澄清:当我在数据库中同时插入一些数据时,我需要将一些数据存储在YML文件中(以供其他用途)

no the data is inserted successfully in the database but it doesn't in the YML file (it always return Unable to write the file) after I tried to use this method which I thought it's gonna work: 在我尝试使用此方法后(我认为它将可以正常工作),没有将数据成功插入数据库中,但没有将其插入YML文件中(它始终返回无法写入文件)。

   $title = $title-en.' :'.$title-fr;
   $this->load->helper('file');
        $msg = "non";
        if (!write_file(base_url().'assets/data/data.yml',$title, 'a+')){
            $msg = 'Unable to write the file';
        }else{
            $msg = 'File written!';
        }

     echo $msg;

You cannot write to a file using a URL ie http://www.domainname.com/assets/data/data.yml 您无法使用URL写入文件,即http://www.domainname.com/assets/data/data.yml

You need to use a PATH. 您需要使用一个PATH。 ie

if (!write_file('.assets/data/data.yml', $title, 'a+')) {
...
}

So if you use the correct path and the file has it's permissions set to writeable, that should help. 因此,如果使用正确的路径,并且文件的权限设置为可写,那应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM