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 » support » symfony 1.3 and 1.4 » symfony 1.4, admin generator and upload image  (5) 1 Vote(s)
symfony 1.4, admin generator and upload image [message #98058] Mon, 26 April 2010 15:39 Go to next message
giorg  is currently offline giorg
Messages: 142
Registered: August 2006
Location: Cesena
Senior Member

Hey guys,

I need to upload an image in the backend (admin generator), and I'm following the chapter 12, but it doesn't work.

In my /lib/form/doctrine/personForm.class I have:

public function configure()
{
parent::configure();

$this->widgetSchema['picture'] = new sfWidgetFormInputFileEditable(array(
'label' => 'Foto',
'file_src' => '/uploads/pictures/'.$this->getObject()->getPicture(),
'is_image' => true,
'edit_mode' => !$this->isNew(),
'template' => '<div class="sublabel">%file%<br />%input%<br />%delete% %delete_label%</div>',
));

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

// create new values for years
$years = range(date('Y') - 80, date('Y') + 80);
$this['birthday']->getWidget()->setOption('years', array_combine($years, $years));
}

but when I save I get the usual

"The item has not been saved due to some errors."

any suggestion?

thanks


/Andrea
Re: symfony 1.4, admin generator and upload image [message #98160 is a reply to message #98058 ] Tue, 27 April 2010 17:09 Go to previous messageGo to next message
Tawl  is currently offline Tawl
Messages: 22
Registered: February 2010
Junior Member
Do you get the error when you have selected a file to upload, or only when you haven't selected one?

If it only happens when you haven't selected a file to upload, it could be something similar to problems I've had where a file upload is defaulting as required => true, forcing you to select a file to upload every time the form is saved (which is a bit of a failing with the sfWidgetFormInputFileEditable widget IMO).

Try this and see if it helps the form to save when no image is selected:

$this->validatorSchema['picture'] = new sfValidatorAnd(array(
			$this->validatorSchema['picture'], new sfValidatorString(array('required' => false)),
		));
Re: symfony 1.4, admin generator and upload image [message #98161 is a reply to message #98160 ] Tue, 27 April 2010 17:15 Go to previous messageGo to next message
giorg  is currently offline giorg
Messages: 142
Registered: August 2006
Location: Cesena
Senior Member

Hey Tawl,

thanks for your answer.

Actually in the meanwhile I found the mistake, was something stupid I forgot. But, solved that, now the picture path is not saved in the db, what is saved is the string "Array".

Any suggestion?

Thanks again.


/Andrea
Re: symfony 1.4, admin generator and upload image [message #98175 is a reply to message #98161 ] Tue, 27 April 2010 23:35 Go to previous messageGo to next message
Tawl  is currently offline Tawl
Messages: 22
Registered: February 2010
Junior Member
Hey Andrea

It's a little tricky to tell what's going on without seeing the full picture. Perhaps if you could post the relevant schema definition for your person and picture, and the entire person form, I might be able to help.

I'm a long way from a Symfony expert myself, but it seems that an awful lot of poeple read this forum but very few reply, so maybe I can help redress that balance.

Cheers,

Tawl
Re: symfony 1.4, admin generator and upload image [message #98189 is a reply to message #98175 ] Wed, 28 April 2010 10:02 Go to previous messageGo to next message
giorg  is currently offline giorg
Messages: 142
Registered: August 2006
Location: Cesena
Senior Member

Hi Tawl,

thank you very much. This is my schema, which could be wrong:

person:
actAs: { Timestampable: ~ }
columns:
firstname: { type: string(255), notnull: true }
lastname: { type: string(255), notnull: true }
birthday: { type: date, notnull: true }
address: { type: string(4000), notnull: true }
phone: { type: string(255) }
picture: { type: string(255) }
team: { type: string(255), unique: true }
note: { type: string(4000) }

visit:
actAs: { Timestampable: ~ }
columns:
person_id: { type: integer, notnull: true }
note: { type: string(4000) }
date: { type: date }
relations:
person: { onDelete: CASCADE, local: person_id, foreign: id }

one person can have one or more visits, is this definition right? I'm asking this 'cause the admin generator doesn't replace the person_id with the person name (through the __toString() function)...

and this is the form:

class personForm extends BasepersonForm
{
public function configure()
{
parent::configure();

$this->widgetSchema['picture'] = new sfWidgetFormInputFileEditable(array(
'label' => 'Foto',
'file_src' => '/uploads/pictures/'.$this->getObject()->getPicture(),
'is_image' => true,
'edit_mode' => !$this->isNew(),
'template' => '<div class="sublabel">%file%<br />%input%<br />%delete% %delete_label%</div>',
));

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

// create new values for years
$years = range(date('Y') - 80, date('Y') + 80);
$this['birthday']->getWidget()->setOption('years', array_combine($years, $years));

unset($this['created_at'], $this['updated_at']);
}
}

thanks a lot


/Andrea
Re: symfony 1.4, admin generator and upload image [message #98234 is a reply to message #98189 ] Wed, 28 April 2010 22:17 Go to previous messageGo to next message
Tawl  is currently offline Tawl
Messages: 22
Registered: February 2010
Junior Member
Hi Andrea

Firstly, to fix your photo upload I think you are missing the sfValidatorFile which sets the directory that images are saved to. Try this for your form configure()

  public function configure()
  {
	parent::configure();

	$this->widgetSchema['picture'] = new sfWidgetFormInputFileEditable(array(
		'label' => 'Foto',
		'file_src' => '/uploads/pictures/'.$this->getObject()->getPicture(),
		'is_image' => true,
		'edit_mode' => !$this->isNew(),
		'template' => '<div class="sublabel">%file%<br />%input%<br />%delete% %delete_label%</div>',
	));

	$this->validatorSchema['picture'] = new sfValidatorFile(array(
		'required'   => false,
		'path'       => sfConfig::get('sf_upload_dir').'/pictures',
		'mime_types' => 'web_images',
	));

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

	// create new values for years
	$years = range(date('Y') - 80, date('Y') + 80);
	$this['birthday']->getWidget()->setOption('years', array_combine($years, $years));
	
	unset($this['created_at'], $this['updated_at']);
  }


Secondly, your schema should work fine as it is. In order for the admin generator to show something friendly instead of the person_id when you use the visit form, you need to override the Baseperson __toString() method to make it use something else.

So in your Person class, do the following:

class Person extends BasePerson
{
	public function __toString()
	{
		return $this->getFirstname().' '.$this->getLastname();
	}
}


That should replace the IDs in the Person drop-down on the Visit form with the person's friendly name.

Let me know how you get on.

Tawl
Re: symfony 1.4, admin generator and upload image [message #98265 is a reply to message #98234 ] Thu, 29 April 2010 11:55 Go to previous messageGo to next message
giorg  is currently offline giorg
Messages: 142
Registered: August 2006
Location: Cesena
Senior Member

hey tawl,

thank you very much, now everything is fine.


/Andrea
Re: symfony 1.4, admin generator and upload image [message #103011 is a reply to message #98058 ] Fri, 23 July 2010 20:19 Go to previous messageGo to next message
madal  is currently offline madal
Messages: 2
Registered: July 2010
Junior Member
hi, i have the same error, but tha answer that we have up doesn't work!

I have this schema:
videos:
columns:
title: { type: string(100), notnull: true }
description: { type: string(5000), notnull: true }
video: { type: string(100), notnull: true }
thumb: { type: string(100), notnull: true }
event_id: { type: integer, notnull: true }
is_activated: { type: boolean, notnull: true, default: 0 }
relations:
events: { onDelete: CASCADE, local: event_id, foreign: id, foreignAlias: events }

after that in the generator.yml i have
config:
form:
class: backendThumb

Into backendThumb.class.php i have

class BackendThumb extends videosForm
{
public function configure()
{
parent::configure();

$this->widgetSchema['thumb'] = new sfWidgetFormInputFileEditable(array(
'label' => 'thumb',
'file_src' => '/uploads/'.$this->getObject()->getThumb(),
'is_image' => true,
'edit_mode' => !$this->isNew(),
'template' => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>',
));

$this->validatorSchema['thumb'] = new sfValidatorFile(array(
'required' => false,
'path' => '/uploads/',
'mime_types' => 'web_images',
));

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

// ...
}


and nothing... I can't understand where is my mistake!

Can anybody help me, please !!!
Re: symfony 1.4, admin generator and upload image [message #103013 is a reply to message #98058 ] Fri, 23 July 2010 20:35 Go to previous message
madal  is currently offline madal
Messages: 2
Registered: July 2010
Junior Member
i have the result into db, but i don't have anything in uploads directory. I don't have the file!
Previous Topic:Propel converts őŐűŰ character to html_entity
Next Topic:Problème d'insertion SQL avec relation sur doctrine
Goto Forum:
  

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