1

我已将图像存储在我的 Yii 项目中的图像文件夹(根)中。我想在受保护/视图/学院中的 CDetailView 中显示图像

我的代码

array(
            'label'=>'CollegeLogo',
            'type'=>'raw',
            'value'=>CHtml::image("../".Yii::app()->baseUrl."/Images/".$model->CollegeLogo),

        ),

它不工作

4

5 回答 5

3
<?php 

$this->widget('zii.widgets.CDetailView', array(

    'data'=>$model,
    'attributes'=>array(
        'title',
        'date',
        'description',
         array(
            'type' => 'raw',
            'value'=>CHtml::image(Yii::app()->baseUrl."/upload/".$model->image,'alt',array("width"=>"50px" ,"height"=>"50px"))
            ),
        'time',
        'user_id',
    ),
)); ?>
于 2014-09-08T05:36:14.367 回答
2

"../"在您的代码中删除。Baseurl 将返回根文件夹的路径。

'value'=>CHtml::image(Yii::app()->baseUrl."/Images/".$model->CollegeLogo),
于 2014-02-11T06:57:24.770 回答
1

尝试这个

'value'=>CHtml::image(Yii::app()->getBaseUrl(true) . '/Images/'.$model->CollegeLogo),
于 2014-02-11T11:19:40.293 回答
0

此代码有效

array(
            'label'=>'CollegeLogo',
            'type'=>'raw',
            'value'=>CHtml::tag('img',
                array("title"=>"CollegeLogo",
                "src"=>Yii::app()->baseUrl."/CollegeImages/".$model->CollegeLogo,
                "style"=>"height:70px")
            )
        ),
于 2014-02-12T05:09:26.970 回答
0

最简单的方法是使用带有图像类型的字符串格式 "Name:Type:Label"

<?php
'attributes' => array(
  "CollegeLogo:image",
  //...
),

如果该CollegeLogo属性不返回绝对 url,我将在返回它的模型中创建一个虚拟属性:

public function getCollegeLogoUrl() {
    return "../".Yii::app()->baseUrl."/Images/".$model->CollegeLogo;
}

然后在小部件中使用它:

<?php
'attributes' => array(
  "collegeLogoUrl:image",
  //...
),
于 2014-02-11T13:16:43.893 回答