Development

#5434 (sfDoctrinePlugin - forms - user filename generator function)

You must first sign up to be able to contribute.

Ticket #5434 (new defect)

Opened 6 months ago

Last modified 3 weeks ago

sfDoctrinePlugin - forms - user filename generator function

Reported by: mgmarcum Assigned to: fabien
Priority: major Milestone:
Component: form Version: 1.2.0
Keywords: sfDoctrine Forms Cc:
Qualification: Unreviewed

Description

Hi,

I saw in the jobeet doctrine tutorial a method of having a function in your form the would generate filenames for uploaded files:

if a generateLogoFilename() method exists in the form, it will be called by the validator and the result will override the default generated logo filename. The method is given the sfValidatedFile object as an argument.

This wasn't working for me so I went to the source code and saw on line, 503 of sfValidatorFile.class.php

else if (method_exists($this->object, $method)){
   return $this->getValue($field)->save($this->object->$method($this->getValue($field)));
}

I changed this to :

else if (method_exists($this, $method)){
   return $this->getValue($field)->save($this->$method($this->getValue($field)));
}

and now the code works the way the doc says (the function is in the form class). The way the code was working the generate[column]Filename () would have to be in the model class. I also noticed that the function name is not expecting a camelCase version of the column name, which sort of goes against convention.

Change History

12/31/08 05:55:38 changed by mgmarcum

  • priority changed from minor to major.

Sorry, the file that this code referes to is:

lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/for/sfFormDoctrine.class.php @ line 503

not sfValidatorFile.class.php

01/05/09 17:46:15 changed by mgmarcum

did an svn up this morning and saw that this file was updated in .r14465 , but this bug wasn't fixed. However I did notice that the self::camelize($field) was used in another part of the file, so I changed my code to use this function too:

sfFormDoctrine.class.php @ 497:

$method = sprintf('generate%sFilename', self::camelize($field));

if (!is_null($filename)) {

return $this->getValue($field)->save($filename);

} else if (method_exists($this, $method)) {

return $this->getValue($field)->save($this->$method($this->getValue($field)));

} else {

return $this->getValue($field)->save();

}

01/29/09 00:39:09 changed by FabianLange

  • owner changed from fabien to Jonathan.Wage.

02/03/09 23:11:35 changed by Jonathan.Wage

  • owner changed from Jonathan.Wage to fabien.

This problem exists for both propel and Doctrine. Fabien, can you decide what we should do? The user states the documentation says the function is to be placed in the form class, but the code for both propel and Doctrine check for the method to exist on the object.

06/17/09 11:56:28 changed by virtualize

  • component changed from plugins to form.

This Problem still exists. I'm on Symfony 1.2.7 / Doctrine. Setting up a generate[Column]Filename() in Model works, but only on compact column names like 'thumb'. It fails if the column name has an underscore like 'video_thumb' and therefore the function name needs to be camelCased (generateVideoThumbFilename)

06/17/09 11:56:43 changed by virtualize

  • milestone set to 1.2.8.

06/17/09 14:26:47 changed by FabianLange

  • milestone deleted.

please do not set milestones

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.