【发布时间】:2016-04-21 10:05:11
【问题描述】:
我想从数据库中显示data,并且我在model file 中创建了函数,它显示来自数据库的数据,但所有值都显示在array format 中。
问题是当我在 foreach 循环中打印 echo $values['title']; 时,它只显示来自 title 数组的第一个字母??
型号代码
function reviewcitypage()
{
$cacheKey = 'city_page';
GigaCache::set(array('duration'=>"+1 minutes",'path'=>CACHE));
$cachedCategoryData = GigaCache::read($cacheKey);
if($cachedCategoryData && !cr('DynamicPage.field'))
{
$recentactivity = $cachedCategoryData;
}else
{
$recentactivity= $this->find("list",array("conditions"=>array("status"=>1),'fields'=>array('title','body','rating'),'recursive'=>-1,'limit'=>10));
//dont't set cache if dynamic field
if(!cr('DynamicPage.field'))
{
GigaCache::set(array('duration'=>"+1 minutes",'path'=>CACHE));
GigaCache::write($cacheKey,$recentactivity);
}
}
return $recentactivity;
}
查看文件
$ReviewObj = cri('Review');
$recentactivity = $ReviewObj->reviewcitypage();
foreach ($recentactivity as $name => $value){
foreach($value as $values)
{
echo $values['title'];
}
}
**问题已解决,感谢支持**
i have changed the code in model file and it is woking now
$recentactivity= $this-
>find("all",array("conditions"=>array("status"=>1),'recursive'=>-1,
'limit'=>10));
【问题讨论】:
-
echo "<pre/>";print_r($recentactivity);的输出是什么。给我们看 -
@Anant 我想在视图文件中将
data显示到不同的 div 中
标签: php cakephp module model controller