This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » Dynamic folder in sfWidgetFormInputFileEditable
Dynamic folder in sfWidgetFormInputFileEditable [message #80771] Fri, 26 June 2009 21:29 Go to next message
pascal.burkhard  is currently offline pascal.burkhard
Messages: 6
Registered: June 2009
Junior Member
I have the following problem : I want to be able to have an editable image in my backend form for an element called Horse. This element has a field "Image" that contains the name of the image and that image has to be stored in "uploads/images/pferde/%name_slug%/" where %name_slug% is a slugified value of the field "Name".

Now below you have my BackendKdHorseForm with the widgetSchema and validatorSchema for the field "Image". It works perfectly fine as long as I am editing a Horse, but when I try to creat a new one it uploads the image into "uploads/images/pferde/" instead of "uploads/images/pferde/%name_slug%". Now I am guessing that in the creation process the validatorSchema for "Image is unable to find a value for $this->getObject()->getNameSlug() and thats why my image ends up in "uploads/images/pferde/", my question is how can I modify this validatorSchema in order for the creation process to upload the image in the right place.

Just for information I did try to use Kd::slugify($this->getValue ('name')) instead of $this->getObject()->getNameSlug() but it still didn't work...
class BackendKdHorseForm extends KdHorseForm
{
	public function configure()
	{
		parent::configure();
			
		$this->widgetSchema['image'] = new sfWidgetFormInputFileEditable(array(
	    		'label'     => 'Bild',
			'file_src'  => '/uploads/images/pferde/'.$this->getObject()->getNameSlug().'/'.$this->getObject()->getImage(),
			'is_image'  => true,
			'edit_mode' => !$this->isNew(),
			'template'  => '<table class="null"><tr><td colspan="2">%file%</td></tr><tr><td  colspan="2">%input%</td></tr><tr><td>%delete%</td><td>%delete_label%</td></tr></table>',
		));
	
		$this->validatorSchema['image'] = new sfValidatorFile(array(
			'required'   => false,
			'path'       => sfConfig::get('sf_upload_dir').'/images/pferde/'.$this->getObject()->getNameSlug(),
			'mime_types' => 'web_images',
			'validated_file_class' => 'sfValidatedFileOriginalName'
		));

		$this->validatorSchema['image_delete'] = new sfValidatorPass();
	}
}

[Updated on: Fri, 26 June 2009 21:29]

Re: Dynamic folder in sfWidgetFormInputFileEditable [message #81166 is a reply to message #80771 ] Sat, 04 July 2009 23:08 Go to previous messageGo to next message
pascal.burkhard  is currently offline pascal.burkhard
Messages: 6
Registered: June 2009
Junior Member
Nobody has any ideas ?
Re: Dynamic folder in sfWidgetFormInputFileEditable [message #81167 is a reply to message #80771 ] Sun, 05 July 2009 01:21 Go to previous messageGo to next message
Levelx  is currently offline Levelx
Messages: 358
Registered: April 2009
Location: Germany
Faithful Member
I guess you have to set the 'file_src' option at a later time.

Maybe in the doSave method (you have to override) or in the action before the save method is called with something like
$form->getWidget('image')->setOption('file_src', your_wished_file_source),


Because as I understand it, you want to change the to be used directory now during the execution of the 'configure' function. But this method will only be executed when the form is created. But the value that you want to use will be entered from the user at a later time.

What happens when you edit your element upload an new image and change the name (if possible)? I guess that new picture is stored in the directory with the old name, because you set the value when you create the form.

Just some ideas and I hope they will help you!

[Updated on: Sun, 05 July 2009 01:23]

Re: Dynamic folder in sfWidgetFormInputFileEditable [message #97819 is a reply to message #80771 ] Thu, 22 April 2010 00:31 Go to previous message
quisoc  is currently offline quisoc
Messages: 14
Registered: March 2008
Junior Member
I've the same problem.
I've tried this solution, but $form is a undefined variable.
Anybody has the solution?
Previous Topic:strange doctrine PDO error
Next Topic:[SOLVED] admin-gen + dropdown list filter customization
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software