【发布时间】:2015-04-14 13:22:20
【问题描述】:
我正在尝试将数据插入 MySQL 数据库。
这是我的表单,在 action.class.php $this->formTodo = new LpTodoGeneralForm();
而 LpTodoGeneralForm.class.php 是:
<?php
class LpTodoGeneralForm extends BaseFormDoctrine{
public function configure(){
$this->widgetSchema['deadline_date'] = new sfWidgetFormInputText(array(), array('class' => 'input-text small datepicker', 'readonly' => 'readonly'));
$this->widgetSchema['firm_name'] = new sfWidgetFormInputText(array(), array('class' => 'input-text datepicker'));
$this->validatorSchema['todo_by'] = new sfValidatorPass(array('required' => true));
$this->widgetSchema['todo_by'] = new sfWidgetFormInputText(array(), array('class' => 'input-text small datepicker', 'readonly' => 'readonly'));
}
public function setup(){
$this->setWidgets(array(
'done' => new sfWidgetFormInputCheckbox(),
'deadline' => new sfWidgetFormInputCheckbox(),
'deadline_date' => new sfWidgetFormInputText(),
'firm_name' => new sfWidgetFormInputText(),
'description' => new sfWidgetFormTextarea(),
'todo_by' => new sfWidgetFormInputText(),
));
$this->widgetSchema->setNameFormat('todo[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
$this->setupInheritance();
parent::setup();
}
public function getModelName(){
return 'Todo';
}
}
在提交表单时,我在 action.class.php 中获取帖子数据。 我的挑战是如何将这些数据插入到数据库中。
【问题讨论】:
-
谢谢,我已经完成了。为此创建了架构并生成了模块。但现在我面临另一个问题,收到错误 Unexpected extra form field named "deadline_date"。
-
每个表单字段都必须有一个对应的验证器对,所以为
deadline_date添加一个验证器。 -
请看一下:我已经提出了另一个问题:stackoverflow.com/questions/29744485/…
标签: php doctrine symfony-1.4