0

I'm trying to set up a scenario in Yii. I have a model called File, which I use for a file upload. Now, I want to use the same model for the creation of directories. Directories don't have a file attribute so I setup the scenatio in the model like this:

public function rules()
{
  return array(
    array('file', 'file', 'types'=>'jpg, gif, png, jpeg, bmp', 'maxSize'=>1024 * 1024 * 10, 'tooLarge'=>'Bestand moet kleiner dan 10MB zijn.'),
    array('file', 'file', 'on'=>'makefolder', 'allowEmpty'=>true),
  );
}

In the controller I trigger the scenatio with $model = new File("makefolder"); Even now I always get the error that 'File cannot be blank'. I used this page as documentation.

j0k
  • 22,600
  • 28
  • 79
  • 90
Thijs
  • 3,015
  • 4
  • 29
  • 54

1 Answers1

2

Just a guess (because your original code seems fine to me) but you could try to set that the first rule is valid for all the scenarios except makefolder:

public function rules()
{
  return array(
    array('file', 'file', 'types'=>'jpg, gif, png, jpeg, bmp', 'maxSize'=>1024 * 1024 * 10, 'tooLarge'=>'Bestand moet kleiner dan 10MB zijn.', 'except'=>'makefolder'),
    array('file', 'file', 'on'=>'makefolder', 'allowEmpty'=>true),
  );
}

With those rules is the error still here?

But upload a file and create a folder is not the same thing, you should use 2 distincts models!

darkheir
  • 8,844
  • 6
  • 45
  • 66