视图文件 $form=$this->beginWidget('CActiveForm', array( 'id'=>'registration-form', 'enableAjaxValidation'=>true, 'htmlOptions' => array('enctype' => 'multipart/form-data'), )); ?> <div > <div> php echo $form->labelEx($model,'csv_file'); ?> php echo $form->fileField($model,'csv_file'); ?> php echo $form->error($model, 'csv_file'); ?> div> <hr> php echo CHtml::submitButton('Upload CSV',array("class"=>"")); ?> php echo $form->errorSummary($model); ?> div>php $this->endWidget(); ?>
模型文件 public function rules() { array('csv_file', 'file', 'types' => 'csv', 'maxSize'=>5242880, 'allowEmpty' => true, 'wrongType'=>'Only csv allowed.', 'tooLarge'=>'File too large! 5MB is the limit'), } public function attributeLabels() { 'csv_file'=>'Upload CSV File', }
控制器文件 public function actionImport() { $model = new Registration; //$file = CUploadedFile::g
|
|