我对Yii2还很陌生,我想知道是否有可能将XML文件加载到activeform中,然后可以上传到数据库中,然后任何具有适当访问权限的人都可以查看这些数据。
我在网上看了看,你可以加载XML文件,但将其显示为原始数据,我看过这些,但我不知道如何将其转换为active-form。
编辑:或者,如果可以直接将XML文件上传到数据库,也可以使用。
发布于 2020-02-28 22:54:11
$model = new XMLFileUpload();
$testupload = new test();
if (Yii::$app->request->isPost)
{
$model->file = UploadedFile::getInstance($model, 'file');
if ($model->file && $model->validate())
{
$model->file->saveAs('uploads/' .$model->file->baseName . '.' . $model->file->extension);
$xmlfile = file_get_contents('uploads/' .$model->file->baseName . '.' . $model->file->extension);
$xmlob = simplexml_load_string($xmlfile);
$xmljson = json_encode($xmlob);
$xmlarray = json_decode($xmljson, true);
$testupload->attributes = $xmlarray;
$testupload->save(false);
}
}https://stackoverflow.com/questions/60450472
复制相似问题