在代码点火器框架中使用php编写YAML文件


Write on YAML file using php in codeigniter Framework

我使用带有codeIgniter的YAML库,我手动添加数据,但现在我决定需要自动添加,我想知道如何在.YML文件的末尾添加一行?

澄清:当我同时在数据库中插入一些数据时,我需要将其中一些数据存储在YML文件中(用于其他用途)

没有,数据成功插入数据库,但没有插入YML文件(它总是返回Unable to write the file)。在我尝试使用这种方法后,我认为它会起作用:

   $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;

您不能使用URL写入文件http://www.domainname.com/assets/data/data.yml

您需要使用PATH。即

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

因此,如果您使用正确的路径,并且文件的权限设置为可写,这应该会有所帮助。