2011-05-11 85 views
0

一个textarea的价值,我似乎无法得到一个textarea的输入的文本。当我这样做时:如何获得在Symfony的

die($request->getPostParameter('comment')) 

它输出单词“数组”。当我print_r()它确实显示textarea是一个数组,它的值存储在数组中。但我不知道如何获得这个价值,所以我可以把它放到一个表格中的一个字段中。

@ greg0ire:我这样做是因为我想将数据保存到两个不同的表。我的html页面显示了一个实际由两个不同类/模型组成的表单。我设法将所有字段保存到除注释字段之外的两个表中。然后我试图获得价值,并意识到它是一个数组,并想知道这是不是导致我的数据不能保存的原因。这就是为什么我问这个问题。我已经问了另一个question,它解释了上下文。

这些都是在点击提交按钮

public function executeUpdateInlineForm(sfWebRequest $request) 
{ 

    $overdueInvestigation = Doctrine_Core::getTable('investigation')->find($request->getParameter('id')); 

    $investigationForm = new investigationInlineForm($overdueInvestigation); 
    $commentForm=new commentForm(); 


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

    $this->processInlineForm($investigationForm, $commentForm); 

    } 

protected function processInlineForm(sfForm $investigationForm, sfForm $commentForm) 
{ 

    if ($investigationForm->isValid()) 
     { 
     $investigation = $investigationForm->save(); 

     $comment = $commentForm->updateObject(); 
     $comment->setInvestigation_id($investigationForm->getObject()->getId()); 
     $comment->setComment($commentForm->getObject()->getComment()); 
     $comment->setuserId($investigationForm->getObject()->getCreatedUserId()); 
     $comment->setDateEntered(time()); 
     $comment->save(); 
     $this->redirect('investigation/overdue/'); 
    } 


} 
+0

为什么把我的问题记下来?知道symfony和php的人看起来很容易,但我不知道! – Nicola 2011-05-11 11:31:01

+0

1以平衡的不合理downvote – greg0ire 2011-05-11 13:03:08

+0

可能重复的[如何从在Symfony的一种形式中更新2代表?](http://stackoverflow.com/questions/5961527/how-to-update-2-tables-from-one -form-in-symfony) – greg0ire 2011-05-11 14:25:55

回答

2

,你可以简单地存储$request->getPostParameter('comment')在数组中,并在这个阵列上使用array_pop()运行的功能,但我认为这将是更好地理解你为什么获得一个数组。我认为textarea的名称必须是comment[],当它应该可能只是comment

UPDATE

阅读您的更新和您的其他问题后,似乎你需要为你的域命名约定:

<input type="text" name="investigation[field1]"/> 
<input type="text" name="investigation[field2]"/> 
<input type="text" name="investigation[field3]"/> 
<input type="text" name="comment[content]"/> 

使用setNameFormat()方法上的表单的小部件架构为了实现这一点,然后将您的调查表格绑定到investigation请求参数中,并将您的评论表格绑定到comment参数上,那么您会很好。

祝你好运!

+0

@greg我感谢您的意见,我已经更新了上面的问题,使其更清晰,而不是添加评论代码。 – Nicola 2011-05-11 13:25:22

+0

谢谢。我已经设法改变评论字段的nameFormat,它的名字就是'comment'。我现在可以得到罚款。我现在的问题是,当我试图将请求绑定到$ comment时,我得到这个错误:Warning:array_key_exists()[function.array-key-exists]:第一个参数应该是一个字符串或C: \ xampp \ htdocs \ tracking \ lib \ vendor \ symfony \ lib \ util \ sfParameterHolder.class.php 53行 – Nicola 2011-05-16 11:48:35

+0

看起来$ request-> getParameter($ commentForm-> getName()没有返回任何东西,因此我的绑定功能没有获得两个paramters(可能是没有得到第二任)的一个 – Nicola 2011-05-16 12:10:57