Created
December 22, 2010 17:06
-
-
Save ftassi/751766 to your computer and use it in GitHub Desktop.
BaseFormDoctrine con metodi per la configurazione di file uploads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Project form base class. | |
* | |
* @package versace | |
* @subpackage form | |
* @author Your name here | |
* @version SVN: $Id: sfDoctrineFormBaseTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ | |
*/ | |
abstract class BaseFormDoctrine extends sfFormDoctrine | |
{ | |
public function setup() | |
{ | |
parent::setup(); | |
} | |
/** | |
* Imposta validatori e widget per i campi "upload" generici | |
* | |
* @param array $fields | |
*/ | |
protected function setUploadField($field, $widgetConf, $validatorConf) | |
{ | |
$this->widgetSchema[$field] = new sfWidgetFormInputFileEditable($widgetConf); | |
$this->validatorSchema[$field] = new sfValidatorFile($validatorConf); | |
$this->validatorSchema[$field . '_delete'] = new sfValidatorBoolean(array('required'=>false)); | |
} | |
/** | |
* Imposta validatori e widget per upload video | |
* Enter description here ... | |
* @param unknown_type $fields | |
*/ | |
protected function setUploadVideo($fields) | |
{ | |
foreach ($fields as $field) | |
{ | |
$widgetConf = array( | |
'file_src' => '/uploads/' . $this->getObject()->get($field), | |
'edit_mode' => true, | |
'is_image' => false, | |
'with_delete' => true, | |
); | |
$validatorConf = array( | |
'required' => false, | |
'path' => sfConfig::get('sf_upload_dir'), | |
'max_size' => 104857600, | |
'mime_categories' => 'web_images', | |
); | |
$this->setUploadField($field, $widgetConf, $validatorConf); | |
} | |
} | |
/** | |
* Imposta validatori e widget per upload immagini | |
* | |
* @param $fields | |
*/ | |
protected function setUploadImage($fields) | |
{ | |
foreach ($fields as $field) | |
{ | |
$widgetConf = array( | |
'file_src' => '/uploads/' . $this->getObject()->get($field), | |
'edit_mode' => true, | |
'is_image' => true, | |
'with_delete' => true, | |
); | |
$validatorConf = array( | |
'required' => false, | |
'path' => sfConfig::get('sf_upload_dir'), | |
'max_size' => 1024000, | |
'mime_categories' => 'web_images', | |
); | |
$this->setUploadField($field, $widgetConf, $validatorConf); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Product form. | |
* | |
* @package versace | |
* @subpackage form | |
* @author Your name here | |
* @version SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ | |
*/ | |
class ProductForm extends BaseProductForm | |
{ | |
public function configure() | |
{ | |
parent::configure(); | |
$this->setUploadImage(array('image_front', 'image_rear', 'thumb')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment