我有这个 schema.yml:
SdrivingEmpresa:
columns:
idempresa:
type: integer(4)
unsigned: true
primary: true
autoincrement: true
idlogotipo:
type: integer(4)
unsigned: true
primary: true
nombre_empresa:
type: string(250)
notnull: true
ruta_emp:
type: string(45)
notnull: true
autoincrement: false
relations:
SdrivingLogotipo:
local: idlogotipo
foreign: idlogotipo
type: one
SdrivingEmisor:
local: idempresa
foreign: idempresa
type: many
SdrivingMaquina:
local: idempresa
foreign: idempresa
type: many
SdrivingOperador:
local: idempresa
foreign: idempresa
type: many
SdrivingTurno:
local: idempresa
foreign: idempresa
type: many
SfGuardUserProfile:
local: idempresa
foreign: idempresa
type: many
我写了这段代码SdrivingLogotipoForm.class.php
class SdrivingLogotipoForm extends BaseSdrivingLogotipoForm {
public function configure() {
$this->widgetSchema['archivo'] = new sfWidgetFormInputFile(array('label' => ''));
$this->validatorSchema['archivo'] = new sfValidatorFile(array(
'required' => false,
'path' => sfConfig::get('sf_upload_dir'),
'mime_types' => 'web_images',
));
}
}
这在SdrivingEmpresaForm.class.php
:
class SdrivingEmpresaForm extends BaseSdrivingEmpresaForm {
public function configure() {
$logotipo = new SdrivingLogotipo();
$logotipo->setIdlogotipo($logotipo);
$this->embedForm('logotipo', new SdrivingLogotipoForm());
}
}
当我执行该create()
方法时,Empresa 被保存并且 Logotipo 文件也被上传,但是idlogotipo
SdrivingEmpresa 中的字段得到了0
,为什么?我做错了什么?
使用来自的小部件SdrivingEmpresaForm
阅读@1ed 的建议后,我做了一些更改,现在SdrivingEmpresaForm.class.php
有以下代码:
class SdrivingEmpresaForm extends BaseSdrivingEmpresaForm {
public function configure() {
$this->widgetSchema['idlogotipo'] = new sfWidgetFormInputFile(array('label' => ''));
$this->validatorSchema['idlogotipo'] = new sfValidatorFile(array(
'required' => false,
'path' => sfConfig::get('sf_upload_dir'),
'mime_types' => 'web_images',
));
}
public function doUpdateObject($values) {
parent::doUpdateObject($values);
if (isset($this['idlogotipo'])) {
if ($this->isNew()) {
$logotipo = new SdrivingLogotipo();
$this->getObject()->setSdrivingLogotipo($logotipo);
} else {
$logotipo = $this->getObject()->getSdrivingLogotipo();
}
}
}
}
但是当我发送表格时,我收到了这个错误:
SQLSTATE [23000]:违反完整性约束:1048 列 'idlogotipo' 不能为空
并且 logotipo 文件没有上传,也没有创建。有什么帮助吗?