S
S
Sergey Okhonko2015-11-14 01:20:32
Yii
Sergey Okhonko, 2015-11-14 01:20:32

Why file upload validation fails in yii?

Why is the file not validated in YII?
VIEW
<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>
<?php echo CHtml::activeFileField($model, 'media'); ?>
<?php echo Chtml::error($model,'media'); ?>
<?php echo CHtml::submitButton('Next'); ?>
<?php echo CHtml::endForm(); ?>
CONTROLLER
$model=new Loadmix();
$dir=Yii::getPathOfAlias('webroot.mixmarker');
if(isset($_POST['loadmix']))
{
$model->attributes=$_POST['Loadmix'];
$model->media=CUploadedFile::getInstance($model,'media');
if($model->validate()){
...
...
MODEL
public $file;
public function role(){
return array(
array('file','file','types'=>'mp3'),
);
}
Tell me pliz what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-11-14
@sersergei

Read here www.yiiframework.com/wiki/2/how-to-upload-a-file-u...
and if my memory serves me, the function should be called rules rather than role...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question