Ask your Symfony questions! Pay money and get answers fast! (more info)

Why does this fail? Symfony

  • SOLVED

I am getting:

Fatal error: Class 'validators' not found in
/home/dev/cache/aaa/dev/config/modules_mtr_validate_upload.yml.php
on line 14


This is a very simple comment form with just one input, a big textarea. My yaml file:

fields:
caption:
required: Yes
msg: Please provide a caption
myFile:
required: Yes
msg: Please provide a JPEG image file
validators: mtrImageValidator
file: true

mtrImageValidator:
class: sfFileValidator
param:
mime_types:
- 'image/jpeg'
- 'image/pjpeg'
mime_types_error: Only JPEG files are allowed
max_size: 102400
max_size_error: Max size is 10 megabytes

Answers (3)

2010-07-23

Arturo Linares answers:

Don't add the "validators" key, use just the name of the validator:

fields:
caption:
required: Yes
msg: Please provide a caption
myFile:
required: Yes
msg: Please provide a JPEG image file
mtrImageValidator:
file: true

2010-07-23

Loban Rahman answers:

Please resubmit your question with your yaml in a code block so we can ensure you got the tabbing right.


marshall comments:

Loban, I just put the yaml in a block.


Loban Rahman comments:

I should have also asked this earlier? Which version of symfony is this? I'm assuming 1.0.


marshall comments:

Yes, version 1.0. But the first programmer who built this site customized it a lot. In settings.yml and factories.yml, some of the settings were off, like sessions auto_start was set to false, and flash was turned off. A lot of default settings were turned off. So when I see an error like this, I try to keep an open mind. This is the first time we are trying to use validators. For all I know he turned off some default setting about validators.


Loban Rahman comments:

According to Symfony 1.0 documentation at [[LINK href="http://www.symfony-project.org/book/1_0/10-Forms"]]Chapter 10 - Forms[[/LINK]], it should be as follows:

<blockquote>
validators:
mtrImageValidator:
class: sfFileValidator
param:
mime_types:
- 'image/jpeg'
- 'image/pjpeg'
mime_types_error: Only JPEG files are allowed
max_size: 102400
max_size_error: Max size is 10 megabytes

fields:
caption:
required:
msg: Please provide a caption
myFile:
file: true
required:
msg: Please provide a JPEG image file
mtrImageValidator:
</blockquote>

You need to define the "named validators" under "validators:".
You need to put "file: true" directly under the field, it's not part of the FileValidator (Arturo made a mistake here).
Then just refer to the named validator with no parameters.


Loban Rahman comments:

Oops, lets try that again. :-)

According to Symfony 1.0 documentation at [[LINK href="http://www.symfony-project.org/book/1_0/10-Forms"]]Chapter 10 - Forms[[/LINK]], it should be as follows:


validators:
mtrImageValidator:
class: sfFileValidator
param:
mime_types:
- 'image/jpeg'
- 'image/pjpeg'
mime_types_error: Only JPEG files are allowed
max_size: 102400
max_size_error: Max size is 10 megabytes

fields:
caption:
required:
msg: Please provide a caption
myFile:
file: true
required:
msg: Please provide a JPEG image file
mtrImageValidator:


You need to define the "named validators" under "validators:".
You need to put "file: true" directly under the field, it's not part of the FileValidator (Arturo made a mistake here).
Then just refer to the named validator with no parameters.
Also, there is no need for "Yes" after "required:".


marshall comments:

What comes after "mtrImageValidator:"


Loban Rahman comments:

Q: What comes after "mtrImageValidator:"?
A: Nothing!

mtrImageValidator is a "named" validator, in that you defined some default arguments for sfFileValidator, and named it mtrImageValidator. Hence, you just use mtrImageValidator with no parameters, because you have already defined them. Of course, a named validator is only useful if you use it in multiple places, otherwise you could have directly used the sfFileValidator like so:


fields:
caption:
required:
msg: Please provide a caption
myFile:
file: true
required:
msg: Please provide a JPEG image file
sfFileValidator:
mime_types:
- 'image/jpeg'
- 'image/pjpeg'
mime_types_error: Only JPEG files are allowed
max_size: 102400
max_size_error: Max size is 10 megabytes

2010-07-23

GlobalOrangeLab answers:

Hi, you can use this way!

1)

fields:
caption:
required: Yes
msg: Please provide a caption
myFile:
required: Yes
msg: Please provide a JPEG image file
mtrImageValidator:
file: true

validators:
mtrImageValidator:
class: sfFileValidator
param:
mime_types:
- 'image/jpeg'
- 'image/pjpeg'
mime_types_error: Only JPEG files are allowed
max_size: 102400
max_size_error: Max size is 10 megabytes


OR

2)

fields:
caption:
required: Yes
msg: Please provide a caption
myFile:
required: Yes
msg: Please provide a JPEG image file
mtrImageValidator:
file: true


mtrImageValidator:
class: sfFileValidator
param:
mime_types:
- 'image/jpeg'
- 'image/pjpeg'
mime_types_error: Only JPEG files are allowed
max_size: 102400
max_size_error: Max size is 10 megabytes



Hope this will help you!