林尝试将文件上传字段添加到YII一种形式,而其成功地提交和将文件上传到正确的文件夹,它不添加任何数据库。
我只是在学习这个平台,因此任何指导,将是巨大的。
这是我的观点...
<div class="row">
<div class="span4"><?php echo $form->labelEx($model,'slider_image'); ?></div>
<div class="span5"><?php echo $form->fileField($model,'slider_image'); ?></div>
<div class="span3"><?php echo $form->error($model,'slider_image'); ?></div>
</div>
这里是我的控制器...
public function actionEdit() {
$id = Yii::app()->getRequest()->getQuery('id');
$model = CustomPage::model()->findByPk($id);
if (!($model instanceof CustomPage)) {
Yii::app()->user->setFlash('error',"Invalid Custom Page");
$this->redirect($this->createUrl("custompage/index"));
}
if(isset($_POST['CustomPage'])) {
$model->attributes = $_POST['CustomPage'];
$model->image=CUploadedFile::getInstance($model,'slider_image');
if ($model->validate()) {
if ($model->deleteMe) {
$model->delete();
Yii::app()->user->setFlash('info',"Custom page has been deleted");
$this->redirect($this->createUrl("custompage/index"));
} else {
$model->request_url = _xls_seo_url($model->title);
if (!$model->save()) {
Yii::app()->user->setFlash('error',print_r($model->getErrors(),true));
} else {
$model->image->saveAs(Yii::app()->baseUrl.'images/'.$model->image);
Yii::app()->user->setFlash('success',
Yii::t('admin','Custom page updated on {time}.',array('{time}'=>date("d F, Y h:i:sa"))));
$this->beforeAction('edit'); //In case we renamed one and we want to update menu
}
}
}
}
}
和我的模型
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
// other rules
array('slider_image', 'file', 'types'=>'jpg, gif, png'),
);
}
本身整体做工精致的形式,不幸的是我不明白如何YII添加到数据库
谢谢
阿德里安
编辑:香港专业教育学院也明显得到了slider_image
在该表中的字段