我正在尝试检索图片的“url”路径。我对变量 $media 有疑问,它不应该为空
数据库表“媒体”有这个
id|name|url|posts_id|type
媒体控制器.php
function admin_show($id = null){
if($id){
$this->Media->id = $id;
$media = current($this->Media->read());
echo 'results for $media'."\n";
debug($media);
$d['url'] = Router::url('/img/'.$media['url']);//for the Absolute URL
echo 'results for $d'."\n";
debug($d);
}
//I added this line to check if there is any contents in the "Table"
$results = $this->Media->find('all');
echo 'results for $results'."\n";
debug($results);
}
输出如下所示:
results for $media
\app\Controller\MediasController.php (line 47)
false
results for $d
\app\Controller\MediasController.php (line 50)
array(
'url' => '/grafikart2/img/'
)
results for $results
\app\Controller\MediasController.php (line 54)
array(
(int) 0 => array(
'Media' => array(
'id' => '8',
'name' => 'media',
'url' => '2013/11/1003236-10151796510844965-658856574-n.jpg',
'posts_id' => '1',
'type' => 'image'
)
),
我想在我的控制器中检索 $media['url']