--------------------------------------------------------------
// lib/form/StudentForm.class.php
class StudentForm extends BaseStudentForm
{
public function configure()
{
$this->widgetSchema['photo'] = new sfWidgetFormInputFile();
$this->validatorSchema['photo'] = new sfValidatorFile(array(
'path' => sfConfig::get('sf_web_dir').'/uploads/students',
));
}
}--------------------------------------------------------------And write a generatePhotoFilename() method on Student (assuming "Photo" is the phpName for the field name "photo")
--------------------------------------------------------------
// lib/model/Student.php
class Student extends BaseStudent
{
public function generatePhotoFilename(sfValidatedFile $file)
{
return $file->getOriginalName();
}
}
--------------------------------------------------------------
This way is probably the preferred approach as it makes for a thinner controller.


0 意見:
張貼留言