在编辑视图中不显示图像路径


Yii - not showing image path in the edit view

我是新来的。我上传图片。镜像路径到数据库。没关系。当我们更新这些细节时,我需要在表单中显示路径,但每次都是显示没有选择的文件。如何获得正确的图像路径…请任何人可以帮助我?(我使用相同的文件创建和更新一个)。

这是我的视图文件

    <?php   
        echo $form->labelEx($model, 'document');        
        echo $form->fileField($model,'document',array('class'=>'span5','maxlength'=>500));
        echo $form->error($model, 'document');  
    ?>

您可以这样显示图像:

<?php echo CHtml::image(Yii::app()->request->baseUrl.$model->document,"document"); ?>

如果你只想要路径,那么这样做:

 <?php echo Yii::app()->request->baseUrl.$model->document; ?>

然后在更新函数中使用下面的代码更新图像,如果浏览了新图像。

$uploadedFile=CUploadedFile::getInstance($model,'document');
            if($model->save())
            {
                if(!empty($uploadedFile))  // check if uploaded file is set or not
                {
                    $uploadedFile->saveAs(Yii::app()->baseUrl.$model->document);
                }
            }