Hi guys!
I am encountering an issue with admin generator embedded form file
upload, been strugling with it for 2 days, so i would like to ask for
your help.The idea is this :
I have to tables :
GeneralArticle which will embed N General Image forms:
The schema is as follows:
general_article:
_attributes: { phpName: GeneralArticle,
idMethod: native}
id: ~
category_id: { type: integer, foreignTable:
category, foreignReference: id, required: true }
title: { type: varchar(255) }
teaser: { type: varchar(255) }
body: { type: longvarchar }
slug: {type: varchar(255)}
published: {type: tinyint}
published_date: {type: timestamp}
created_at:
updated_at:
general_image:
_attributes: { phpName: GeneralImage, idMethod:
native }
id: ~
article_id: { type: integer, foreignTable:
general_article, foreignReference: id, required: true }
imagefile: { type: varchar(255) }
title: { type: varchar(255) }
published: { type: tinyint }
created_at:
updated_at:
I have succesfully emebed the forms using the article found here:
http://dev.markhaus.com/blog/2008/12/a-way-to-edit-n-1-relationships-in-one-form-with-symfony-12/
And everything worked well (imagefile field being a simple input
widget, also after saving i observed that the values where not
repopulated in the embeded forms), then i started to change the
imagefile field to a file upload field, also used the scriplet from:
http://stereointeractive.com/blog/2008/12/23/symfony-12-upload-a-file-inside-an-embedded-form/
to make the file upload work, But nothing, only get this error
Fatal error: Call to a member function getExtension() on a non-object
in /home/ispa/workspace/timnews/lib/form/GeneralImageForm.class.php on
line 39
I attach also my 2 form classes:
class GeneralImageForm extends BaseGeneralImageForm
{
protected static $publishOptions = array(0=>'NO', 1=>'YES');
protected function updateImagefileColumn($value)
{
// if the user has not submitted an image,
// remove the value from the values as we want
// to keep the old one
if (!$value)
{
return false;
}
$oldPhoto = $this->getObject()->getImagefile();
$path = sfConfig::get('sf_upload_dir').'/general_articles/';
$thumbPath = sfConfig::get('sf_upload_dir').'/general_articles/
thumbs/';
// remove the old photo
if(file_exists($path.$oldPhoto) && is_file($path.$oldPhoto))
{
unlink($path.$oldPhoto);
unlink($thumbPath.$oldPhoto);
}
$file = $value;
// save the photo on the disk
$filename = "article-".time().$file->getExtension($file-
>getOriginalExtension());
$file->save($path.'/'.$filename);
$thumbnail = new sfThumbnail(200, 200,true,false);
$thumbnail->loadFile($path.$filename);
$thumbnail->save($thumbPath.$filename, 'image/jpeg');
// change the value to the new file name
return $filename;
}
protected function removeFields()
{
unset($this['created_at'], $this['updated_at'], $this
['article_id'], $this['id']);
}
public function configure()
{
self::removeFields();
$this->widgetSchema['title'] = new sfWidgetFormInput();
$this->widgetSchema['published'] = new sfWidgetFormSelect(array
('choices' => self::$publishOptions));
$this->widgetSchema['imagefile'] = new sfWidgetFormInputFile
();
$this->setValidators(array(
'title'=> new sfValidatorString(
array
('required'=>false, 'max_length'=>100, 'min_length'=>2 ),
array(
'min_length' =>
'The NAME "%value%" is too short. It must be of %min_length%
characters at least.',
'max_length' =>
'The NAME "%value%" is too long. It must be of %max_length% characters
at most.',
)
),
'published' => new sfValidatorChoice(array('choices' =>
array_keys(self::$publishOptions))),
'imagefile'=> new sfValidatorString(
array
('required'=>false, 'max_length'=>100, 'min_length'=>2 ),
array(
'min_length' =>
'The NAME "%value%" is too short. It must be of %min_length%
characters at least.',
'max_length' =>
'The NAME "%value%" is too long. It must be of %max_length% characters
at most.',
)
),/* new
sfFileImageValidator(array(
'min_height'=>
200,
'min_width'=>
200,
'max_height'=>
700,
'max_width'=>
480,
'path' => sfConfig::get
('sf_upload_dir').'/general_articles',
'required' => false,
'max_size' =>
'1024000',
'mime_types' => array
('image/jpeg')
),
array(
'max_size' => 'The
maximum file size is "%max_size%".',
'mime_types' => 'The
accepted file types are JPG, JPEG',
'min_width' => 'The
image width is too small, it must have minimum 200px',
'min_height' => 'The
image height is too small, it must have minimum 200px',
'max_width' => 'The
image width is too large, it must have maximum 700px',
'max_height' => 'The
image height is too large, it must have maximum 480px',
)
),*/
));
$this->widgetSchema->setLabel('title', 'Titlul imagini');
$this->widgetSchema->setLabel('imagefile', 'Imagine');
$this->widgetSchema->setLabel('published', 'Publicat?');
}
}
class GeneralArticleForm extends BaseGeneralArticleForm
{
public function bind(array $taintedValues = null, array
$taintedFiles = null)
{
$ret = parent::bind($taintedValues, $taintedFiles);
foreach ($this->embeddedForms as $name => $form)
{
$this->embeddedForms[$name]->isBound = true;
$this->embeddedForms[$name]->values = $this->values[$name];
}
return $ret;
}
protected function processForm(sfWebRequest $request, sfForm $form)
{
$this->getUser()->setAttribute('N1added', 0);
parent::processForm($request, $form);
}
protected function removeFields()
{
unset($this['created_at'], $this['updated_at'], $this['slug'],
$this['id'], $this['published'], $this['published_date']);
}
public function configure()
{
self::removeFields();
$n = 0;
foreach($this->object->getGeneralImages() as $image)
{
$n++;
$this->embedForm('imageform_'.$n, new GeneralImageForm($image));
}
if(sfContext::getInstance()->getUser()->hasAttribute('N1added'))
{
for($i=0; $i < sfContext::getInstance()->getUser()->getAttribute
('N1added'); $i++)
{
$generalImage = new GeneralImage();
$generalImage->setGeneralArticle($this->object);
$n++;
$this->embedForm('imageform_'.$n, new GeneralImageForm
($generalImage));
}
}
$this->widgetSchema['title'] = new sfWidgetFormInput();
$this->widgetSchema['body'] = new sfWidgetFormTextareaTinyMCE(array
(
'width' => 450,
'height' => 350,
'config' => '
plugins: "paste",
theme_advanced_disable: "anchor,image,cleanup,help",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword"',
), array('class'=>'tinyMCE'));
$this->widgetSchema['teaser'] = new sfWidgetFormTextareaTinyMCE
(array(
'width' => 450,
'height' => 350,
'config' => '
plugins: "paste",
theme_advanced_disable: "anchor,image,cleanup,help",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword"',
), array('class'=>'tinyMCE'));
$this->setValidators(array(
'title'=> new sfValidatorString(
array
('required'=>true, 'max_length'=>255, 'min_length'=>5 ),
array(
'required' =>
'The TITLE field is required.',
'min_length' =>
'The TITLE "%value%" is too short. It must be of %min_length%
characters at least.',
'max_length' =>
'The TITLE "%value%" is too long. It must be of %max_length%
characters at most.',
)
),
'teaser'=> new sfValidatorString(
array
('required'=>false, 'max_length'=>255, 'min_length'=>5 ),
array(
'min_length' =>
'The TEASER "%value%" is too short. It must be of %min_length%
characters at least.',
'max_length' =>
'The TEASER "%value%" is too long. It must be of %max_length%
characters at most.',
)
),
'body'=> new sfValidatorString(
array
('required'=>false, 'max_length'=>2000, 'min_length'=>5 ),
array(
'min_length' =>
'The BODY "%value%" is too short. It must be of %min_length%
characters at least.',
'max_length' =>
'The BODY "%value%" is too long. It must be of %max_length% characters
at most.',
)
),
'category_id' => new sfValidatorPropelChoice(array('model'
=> 'Category', 'column' => 'id', 'required' => false)),
));
$this->validatorSchema->setOption('allow_extra_fields', true);
$this->validatorSchema->setOption('filter_extra_fields', false);
$this->widgetSchema->setHelp('title','Introduceti titlul
articolului');
$this->widgetSchema->setHelp('teaser','Introduceti descrierea
scurta a articolului');
$this->widgetSchema->setHelp('body','Introduceti corpul
articolului');
$this->widgetSchema->setHelp('category_id','Alegeti categoria
din care face parte acest articol');
}
}
Thank You!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---