Yii:不使用 CDbCriteria 从数据库中获取图像 [英] Yii: Not getting images from database using CDbCriteria
问题描述
我是一个 yiibie.我正在尝试从名为 event
的数据库表中获取图像,并且我正在使用 CDbCriteria
.我对如何使用它有一点了解,但现在我无法从我的数据库中检索图像,可能是我写错了代码或混合了一些东西.通过使用此代码,我没有收到任何错误,我不只是得到图像,请帮助我解决这个问题,谢谢.
limit = 4;$Criteria->order = "id DESC";$Criteria->select = "id, image";$Events = Event::model()->findAll($Criteria);?><div class="row"><h3>事件</h3><?phpforeach ( (array)$Events as $Event){回声"";}?><a href="events.php"><p class="view">查看全部</p></a></div><!--行在此结束-->
第一个也是最明显的错误是在循环中.您的代码应如下所示:
<img src="'.Yii::app()->request->baseurl.'/img 文件夹路径/'.$Event->image.'">";}?>
这应该足以让您的代码工作.您连接字符串的方式(通过使用内部外部字符串)是不正确的.在 PHP 中,字符串由 .
sing.
I am a yiibie.I am trying to get images from my database table named event
and i am using CDbCriteria
. I have a little bit knowledge of how using it but right now i am unable to retrieve the images from my database, might be i am writing my code wrong or mixing few things. By using this code i am not getting any error, i am not just getting the image, please help me with this thing, thank you.
<?php
$Criteria = new CDbCriteria();
$Criteria->limit = 4;
$Criteria->order = "id DESC";
$Criteria->select = "id, image";
$Events = Event::model()->findAll($Criteria);
?>
<div class="row">
<h3>Events</h3>
<?php
foreach ( (array)$Events as $Event)
{
echo "
<div class='col-md-3'>
<div class='thumbnail'>
<img src='<? php echo Yii::app()->request->baseurl;?>$Event->image' >
<div class='caption'>
<a href='join.php'><button class='btn btn-primary center-block'>Join</button></a>
</div>
</div>
</div>
";
}
?>
<a href="events.php"> <p class="view">View all</p></a>
</div><!--row ending here-->
First and most obvious bug is in loop. Your code should look like this:
<?php
foreach ( (array)$Events as $Event)
{
echo "
<div class='col-md-3'>
<div class='thumbnail'>
<img src="'.Yii::app()->request->baseurl.'/img folder path/'.$Event->image.'"> <div class='caption'>
<a href='join.php'><button class='btn btn-primary center-block'>Join</button></a>
</div>
</div>
</div>
";
}
?>
It should be enough to make your code work. The way you were concatenating strings (by using inside outer one) is incorrect. In PHP strings are concatenated by .
sing.
这篇关于Yii:不使用 CDbCriteria 从数据库中获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!