Controller代码:(包括增、改、删)
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new CompanyNews;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['CompanyNews']))
{
$model->attributes=$_POST['CompanyNews'];
if(empty($_POST['CompanyNews']['news_pic'])){
$model->news_pic = $model->news_pic;
}
$file = CUploadedFile::getInstance($model,'news_pic'); //获得一个CUploadedFile的实例
if(is_object($file)&&get_class($file) === 'CUploadedFile'){ // 判断实例化是否成功
$model->news_pic = './assets/upfile/News_file_'.time().'_'.rand(0,9999).'.'.$file->extensionName; //定义文件保存的名称
}else{