您好我也有一个问题,当尝试使用this方法上传图片。从Yii的上传图片显示endWiget()错误
我的动作/型号:
class Image extends CActiveRecord
{
public $foto;
...
public function rules()
{
return array(
...
array('foto', 'file', 'types'=>'jpg, gif, png'),
...
);
}
}
我的控制器:
class ImageController extends Controller
{
public function actionCreate()
{
$model=new Image;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Image']))
{
$model->attributes=$_POST['Image'];
$model->image=CUploadedFile::getInstance($model,'foto');
if($model->save())
$model->foto->saveAs('productimages');
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
}
我的观点:
<?php $form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)
); ?>
<?php echo $form->labelEx($model, 'foto'); ?>
<?php echo $form->fileField($model, 'foto'); ?>
<?php echo $form->error($model, 'foto'); ?>
...
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
但是当我运行,两个问题出现了:
问题#1: endWiget()调用[伊万米西奇解决]
ImageController它认为 “/var/www/html/onlineshop-nimalogos/protected/views/image/_form.php” 包含不正确嵌套插件标签。 CActiveForm小部件没有endWidget()调用。
问题#2: 由于问题#1解决了,出现了另一个问题,图像没有保存在我的'productimages'文件夹中。
请帮我的问题#2非常感谢..
按照本教程http://www.yiiframework.com/wiki/624/upload-image-and-content-using-ajax-and-store-it-in-different-table/ – 2014-09-03 08:31:10
根据消息的错误在文件_form.php中。该视图不会从控制器的这部分调用。 – 2014-09-03 09:50:02