0
我在形式已經這樣configure()
功能:如何在save()函數中訪問no_monitor?
public function configure() {
$this->current_user = sfContext::getInstance()->getUser()->getGuardUser();
unset($this['updated_at'], $this['created_at']);
$this->widgetSchema['idempresa'] = new sfWidgetFormInputHidden();
$id_empresa = $this->current_user->getSfGuardUserProfile()->getIdempresa();
$this->setDefault('idempresa', $id_empresa);
$this->widgetSchema['no_emisor'] = new sfWidgetFormDoctrineChoice(array('model' => 'SdrivingEmisor', 'add_empty' => 'Seleccione un Emisor', 'expanded' => false, 'multiple' => false));
$this->validatorSchema['idempresa'] = new sfValidatorPass();
$this->validatorSchema['no_emisor'] = new sfValidatorPass();
}
而且我需要在save()
功能來定義的關係數據,所以我這樣做:
public function save($con = null) {
$new_machine = parent::save($con);
$relation = new SdrivingMaquinaEmisor();
$relation->setIdmaquina($new_machine);
$relation->setIdemisor();
$relation->save();
return $new_machine;
}
爲了在集Idemisor
,當用戶提交表單時,如何訪問選定的值?這是達到這個目標的最好方法嗎?
編輯需要有關如何訪問no_emisor
值現在我的代碼如下建議 後:
public function save($con = null) {
$new_machine = parent::save($con);
$relation = new SdrivingMaquinaEmisor();
$relation->setIdmaquina($new_machine);
$relation->setIdemisor($this->values['no_emisor']);
$relation->save();
return $new_machine;
}
但我得到這個錯誤:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'idmaquina' cannot be null
出於某種原因$new_machine
沒有按」 t返回最新保存的元素的id
。也許我做錯了,所以我做錯了什麼?
也許但這種方法已經爲我工作了一些其他的時間,我只是不知道如何獲得'no_emisor'的價值 – Reynier
@Reynier看到我的編輯 –
你可以看看我的版嗎? – Reynier