dss524049 2011-09-09 20:19
浏览 33
已采纳

如何从Doctrine2实体填充zend_form?

Right now I'm populating/setDefaults a zend_form like this from the controller:

 $data = array('user' => $account->getUser(), 
            'password' => $account->getPassword(), 
            'name' => $account->getName());

 $form->setDefaults($data);

It's working but seams very manual the process. Is there a better way to do it?

  • 写回答

2条回答 默认 最新

  • douyouzheng2209 2011-09-11 17:29
    关注

    The solution that I apply was to add this function to the entity:

    public function toArray ()
    {
        return get_object_vars($this);
    }
    

    And then just:

    $form->setDefaults($test->toArray());
    

    Also if you need to do it the other way arround (array to object) you can take a look here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站