Saturday, June 30, 2012

Help Upload plugin: validation rules

Hi all,
is anybody using Jose Gonzalez's upload plugin [1]? I have a couple
of open issues regarding its integration inside my web app, but before
filing a bug I wanted to be sure I was doing things the right way.

I attached a couple of validation rules to my Model's attachment
property and they seem to work only while adding a new object to the
database. If I edit an object, all the rules are processed but they
always return true.

public $actsAs = array(
'Upload.Upload' => array(
'attachment' => array(
'mimetypes' => array(
'application/pdf',
)
)
),
);

public $validate = array(
'attachment' => array(
'valid' => array(
'rule' => array('isValidMimeType', array(), false),
'message' => 'File is of an invalid mimetype',
),
),
);

I had a look at the rule code, and on edit operations the function
always exits at its first check:

public function isValidMimeType(&$model, $check, $mimetypes =
array(), $requireUpload = true) {
$field = array_pop(array_keys($check));

if (!empty($check[$field]['remove'])) {
return true;
}

Have you got any idea about this behaviour? $check[$field]['remove']
in my case gets always initialized to 'M'. If I comment out the first
check, then the function will always return false (it looks up the
attachment type using $check[$field]['type'] which is still equal to
'M'). It is really strange both lookups return the same string value.


Thanks,
Matteo

[1] https://github.com/josegonzalez/upload

--
http://www.matteolandi.net/

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: