Forms symfony 1.4条令形式约束

Forms symfony 1.4条令形式约束,forms,symfony1,doctrine,bind,validation,Forms,Symfony1,Doctrine,Bind,Validation,也许是一个简单的问题,我只是错过了一些东西 我有两个表,其中有3个相同的字段(名称/类型) 事件和事件队列 Schema Occurrence: tableName: occurrence columns: id: {the usual} date: {type: date} start_time: {type: time} end_time: {type: time} eid: {a forign key} OccurrenceQueue:

也许是一个简单的问题,我只是错过了一些东西

我有两个表,其中有3个相同的字段(名称/类型)

事件
事件队列

Schema

Occurrence:
  tableName: occurrence
  columns:
    id: {the usual}
    date: {type: date}
    start_time: {type: time}
    end_time: {type: time}
    eid: {a forign key}
OccurrenceQueue:
  tableName: occurrence_queue
  columns:
    id: <-Same As Above->
    occurrence_id: {the usual}
    date: <-Same As Above->
    start_time: <-Same As Above->
    end_time: <-Same As Above->
以下是我失败的尝试:

public function executeEdit(sfWebRequest $request)
{
  $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));

  $this->forward404Unless($occurrence = Doctrine_Core::getTable('Occurrence')->find(array($request->getParameter('id'))), sprintf('Object occurrence does not exist (%s).', $request->getParameter('id')));

  $request->setParameter('occurrence_id',$occurrence->getId());

  $occurrenceQForm = new OccurrenceQueueForm($occurrenceQueue());

  $occurrenceQForm->bind($request->getParameter($occurrenceQForm->getName(),$request->getFiles($occurrenceQForm->getName()));

  if($occurrenceQForm->isValid())
  {
    $occurrenceQForm->save();
    $this->redirect("happyness");
  }
}
这永远不会验证。我假设,因为字段和验证都是一样的,所以都是金色的,不是这样的。所以问题是,我如何完成这项任务?最后,想法是使用
发生队列
表更新
发生


谢谢你的帮助

问题在于表单从未绑定ocurrence\u id。当使用sfForm时,它使用名称格式($form->getName()部分)来生成该字段的名称,因此您可以这样尝试:

DATE: *date picker*
Start Time: HH:MM
End Time: HH:MM
public function executeEdit(sfWebRequest $request)
{
  ...
  $occurrenceQForm = new OccurrenceQueueForm($occurrenceQueue());

  $values = $request->getParameter($occurrenceQForm->getName());
  $values['occurrence_id'] = $ocurrence->getId();
  $occurrenceQForm->bind($values,$request->getFiles($occurrenceQForm->getName()));
  ...
}
public function executeEdit(sfWebRequest $request)
{
  ...
  $occurrenceQForm = new OccurrenceQueueForm($occurrenceQueue(), array('ocurrence' => $ocurrence));
  ...
}
这不是最好的方法,但它会起作用。我真正要做的是将Ocurrence by参数传递给OcurrenceQForm,如下所示:

DATE: *date picker*
Start Time: HH:MM
End Time: HH:MM
public function executeEdit(sfWebRequest $request)
{
  ...
  $occurrenceQForm = new OccurrenceQueueForm($occurrenceQueue());

  $values = $request->getParameter($occurrenceQForm->getName());
  $values['occurrence_id'] = $ocurrence->getId();
  $occurrenceQForm->bind($values,$request->getFiles($occurrenceQForm->getName()));
  ...
}
public function executeEdit(sfWebRequest $request)
{
  ...
  $occurrenceQForm = new OccurrenceQueueForm($occurrenceQueue(), array('ocurrence' => $ocurrence));
  ...
}
在你的发生形式中:

public function OccurrenceQueueForm extends ...{
    public function configure()
    {
        ...
        if($this->getOption('ocurrence') != null){
            $this->setDefault('occurrence_id', $ocurrence->getId());
        }
        ...
   }
}

此外,我还尝试了以下代码:
$SRQ=new-OccurrenceQueue()$SRQ->setOccurrencesId($phpc_occurrences->getOccid())$SRQ->setStarttime($request->getPostParameter('starttime'))$SRQ->setEndtime($request->getPostParameter('starttime')$SRQ->setStartdate($request->getPostParameter('startdate')$OQForm=新发生队列形式($SRQ)$OQForm->save()
$occurrenceQForm->bind($request->getParameter($occurrenceQForm->getName(),$request->getFiles($occurrenceQForm->getName());
应该是
$occurrenceQForm->bind($request->getParameter($occurrenceQForm->getName()),$request->getFiles($occurrenceQForm->->getName());
,应该是什么意思?你能准确点吗“从不验证”(是否有错误消息?)您是否也可以将what
var\u dump($request->getParameter($occurrenceQForm->getName())
显示出来?@greg0ire是的,有语法错误这是psudo代码不是实际的,我的意思是isValid()返回False,这就是为什么…var_dump返回:Null…现在至少我知道它为什么失败了,但我不知道我的请求为什么为Null…?@greg0ire但是$request->getParameter($occurrenceForm->getName())的var_dump是:
array(3){[“startdate”]=>array(3){[“month”=>string(1)“3”[“day”=>string(2)”20“[“年”]=>string(4)“2011”}[“开始时间”]=>array(2){[“小时”]=>string(2)“20”[“分钟”]=>string(1)“0”}[“结束时间”]=>array(2){[“小时”]=>string(2)“21”[“分钟”]=>string(1)“0”}”
也许我把重点放在了错误的问题上,我如何创建一个新表单,向表单添加值,然后保存它?这就是我所要做的一切……我很抱歉错误的引导结构和设置,我显然误解了很多:-)解决方案很简单:停止尝试保存表单,只需保存模型即可……
$occurrenceQueue->setXXX($FORM->getValue('desiredVal');$$occurrenceQueue->save()
这一功能非常有效,符合我的要求。sfForm和doctrine表单之间存在差异。我的建议是,如果您使用的是模型表单,请使用doctrine表单,并始终尝试将表单登录保持在表单内,避免在控制器中使用表单逻辑。按照您所说的方法进行操作,但您会错过doctrine的优点太太