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条)

报告相同问题?

悬赏问题

  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"
  • ¥20 基于决策树的数字信号处理,2ask 2psk 2fsk的代码,检查下报错的原因
  • ¥20 python作业求过程
  • ¥15 wincc已组态的变量过多
  • ¥60 如图:直线与椭圆X轴平行,求直线与椭圆任意一点的相切坐标计算公式
  • ¥50 如何用python使用opencv里的cv::cudacodec::VideoWriter函数对视频进行GPU硬编码
  • ¥100 c#solidworks 二次开发 工程图自动标边线法兰 等折弯尺寸怎么标
  • ¥15 halcon DrawRegion 提示错误
  • ¥15 FastAPI Uvicorn启动显示404
  • ¥15 centos7.9脚本,怎么排除特定的访问记录