Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FileController
- ++++++++++++++++++++++++++++++++++++++++++++
- public function actionCreate()
- {
- $model=new File;
- if(isset($_POST['File']))
- {
- $model->attributes=$_POST['File'];
- $model->tip=CUploadedFile::getInstance($model,'tip');
- if($model->validate())
- {
- $model->save();
- $model->tip->saveAs(Yii::app()->basePath . '/../files/' . $model->tip);
- }
- $this->redirect(array('view','id'=>$model->id));
- }
- $this->render('create',array(
- 'model'=>$model,
- ));
- }
- Model/File.php
- +++++++++++++++++++++++++++++++++++++++++++++++
- public function rules()
- {
- // NOTE: you should only define rules for those attributes that
- // will receive user inputs.
- return array(
- array('nazva, tip', 'required'),
- array('nazva', 'length', 'max'=>30),
- array('tip', 'length', 'max'=>10),
- // The following rule is used by search().
- // Please remove those attributes that should not be searched.
- array('id, nazva, tip', 'safe', 'on'=>'search'),
- array('tip', 'file', 'types'=>'doc, docx, rar, zip, pdf, exe', 'allowEmpty' => true )
- );
- }
- views/file/_form.php
- +++++++++++++++++++++++++++++++++++++++++++
- <div class="form">
- <?php $form=$this->beginWidget('CActiveForm', array(
- 'id'=>'file-form',
- 'enableAjaxValidation'=>false,
- 'htmlOptions'=>array('enctype'=>'multipart/form-data')
- )); ?>
- <p class="note">Fields with <span class="required">*</span> are required.</p>
- <?php echo $form->errorSummary($model); ?>
- <div class="row">
- <?php echo $form->labelEx($model,'nazva'); ?>
- <?php echo $form->textField($model,'nazva',array('size'=>30,'maxlength'=>30)); ?>
- <?php echo $form->error($model,'nazva'); ?>
- </div>
- <div class="row">
- <?php echo $form->labelEx($model,'tip'); ?>
- <?php echo CHtml::activeFileField($model, 'tip'); ?>
- <?php echo $form->error($model,'tip'); ?>
- </div>
- <div class="row buttons">
- <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
- </div>
- <?php $this->endWidget(); ?>
- </div><!-- form -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement