有困難就節省了我的database.In我的行動保存在symfony的1.4動作的照片或文件
if($r->isMethod('post')) {
$this->form->bind($r->getParameter('applicants'), $r->getFiles('applicants'));
//$this->form->bind($r->getParameter('applicants'));
$this->familyForm->bind($r->getParameter('applicant_family_info'));
if($this->form->isValid() && $this->familyForm->isValid()) {
$values = $this->form->getValues();
$familyValues = $this->familyForm->getValues();
$applicantId = Doctrine_Core::getTable('Applicants')->createOrUpdateObject($values, $familyValues, $this->getUser()->getUsername());
$this->getUser()->setFlash('good', 'New applicant record created successfully!');
$this->redirect('loans/new_applicant_loan?applicant_id='.$applicantId);
這將節省輸入數據減去照片column..However,如果我的文件或相片IM添加$ this-> form-> save(); ,這將保存包括照片字段的數據,但照片是重複的,關於如何解決這個問題的任何想法?
與這 - $>形式 - >保存();
,則返回null我刪除$這個 - >形式 - >保存();順便說一句,我有,申請人該兩個表,並applicant_family_info
這ApplicantsTable.class。 PHP
public function createOrUpdateObject($values, $infoValues, $currentLoggedInUser, $obj = null) {
$isUpdate = true;
if(empty($obj)) {
$obj = new Applicants();
$isUpdate = false;
}
$db = $this->getConnection();
$db->beginTransaction();
foreach($values as $k=>$v) {
$obj->$k = $v;
}
if(!$isUpdate) {
$obj->created_by = $currentLoggedInUser;
$obj->date_created = date('Y-m-d H:i:s');
} else {
$obj->updated_by = $currentLoggedInUser;
$obj->date_updated = date('Y-m-d H:i:s');
}
$obj->save();
if(!$isUpdate) {
$applicantId = $db->lastInsertId();
} else {
$applicantId = $obj->id;
}
if(!$isUpdate) {
$info = new ApplicantFamilyInfo();
} else {
$info = $obj->ApplicantFamilyInfo;
}
foreach($infoValues as $k=>$v) {
$info->$k = $v;
}
$info->applicant_id = $applicantId;
$info->save();
$db->commit();
return $applicantId;
}
是的,我需要createOrUpdateObject函數。我想自動填充created_by和updated_by列。 – rai
您可以將'Timestampable'行爲添加到您的表格中,Doctrine會爲您填充它們。 –
謝謝Michal Trojanowski.I會嘗試你的建議。 – rai