这是我的代码
$fid=$node->get("field_vocabulary")->audio;
$file =\Drupal\file\Entity\File::load($fid);
$path = $file->getFileUri();
$json_arr["audio"]=$path;
但它没有用! 为什么呢?
显示此错误
Fatal error: Call to a member function getFileUri() on null in /Applications/MAMP/htdocs/houdun/drupal/modules/article_json/src/Controller/ArticleJsonController.php on line 91
我需要帮助!谢谢!
答案 0 :(得分:3)
我修好了!
$fid=$node->get("field_vocabulary")->audio;
$file =File::load($fid);
$path = file_create_url($file->getFileUri());
$arr["audio"]=$path;
或
$fid=$node->get("field_vocabulary")->audio;
$file =File::load($fid);
$path = $file->url();
$arr["audio"]=$path;