Can... open... worms... everywhere...
Well, I'm going through opening tickets and fixing some basic things as I go along. There's a lot of stuff to clean up on that page!
To explain your particular problem, which is most certainly a bug, this code:
- Code: Select all
// we need the base directory
if (!$this->validatorSchema[$field]->getOption('path'))
{
return $values[$field];
}
Is the culprit. Because the file validator actually returns an object (sfValidatedFile) from it's doClean() method, that is what is contained in $values[$field]. From the code above, you can see that if the path is not set, this object is returned. This object is what gets passed through the chain to be saved in the database, and since object != string you get the type validation error.
If a path
is set, the code continues and eventually the value of $file->save() is returned. Since this method (assuming the user is using the sfValidatedFile default and hasn't specified their own) returns the filename of the saved file, the type validator is happy when it comes to save it in the database as a string.
So there are multiple problems here - another thing interestingly is that Doctrine is automatically calling the $file->save() function when the form is submitted, so there is no need for the duplicate call in Listing 4-27, essentially the file is being saved twice! Well, it's being saved, then unlinked, then saved again...
So, this page needs seriously updating... sheesh.