看板 PHP 關於我們 聯絡資訊
大家好,小弟是PHP初學者, 最近練習使用symfony搭配doctrine時, 遇見無法正確寫入資料的問題。 public function registerAction() { $account = new Account(); $account->setUsername("eric"); $account->setPassword("777"); $account->setMoney("100"); $em = $this->getDoctrine()->getManager(); $em->persist($account); $em->flush(); $accounts = $em->getRepository('AppBundle:Account'); $account = $accounts->findAll(); ... } 執行完撈回來的資料只有money有正確寫入,剩下的都是null。 但是最新的一筆卻又是正常的。 [{"id":1,"username":null,"password":null,"money":100}, {"id":2,"username":null,"password":null,"money":100}, {"id":3,"username":"eric","password":"777","money":"100"}] 另外如果不新增資料,直接去撈出來連最新一筆都會是失敗的。 {"id":3,"username":null,"password":null,"money":100}] 想請問問題可能出在哪? ----------------------------------------- 第一次在本版發問, 若問的方法或格式有問題再麻煩指正,謝謝! 附上log 與 整理過的網頁版 dev.log: https://i.imgur.com/lq527oU.png 網頁版: https://hackmd.io/s/H1i36t6fZ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.117.36.235 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1497359371.A.EFA.html ※ 編輯: qweasd777 (122.117.36.235), 06/14/2017 00:09:43
rickysu: 請自行開啟 debug tool bar,看發生什麼事吧。 06/14 10:00
rickysu: 你可以透過 /_profiler/ 去觀看 06/14 10:02
g9308370: http://imgur.com/YoRE6Pf 06/14 10:14
g9308370: 可以嘗試看看把column name也加進@ORM\Column 06/14 10:16
qweasd777: 後來在專案上照g93大的方法成功了,十分感謝~ 06/14 19:45
qweasd777: 也謝謝ricky大的提示 好強的功能 以後會多加利用 06/14 19:51