zf2 に挿入されたレコードの ID を取得したい。PHPでscope_identityを使用して解決策を見つけました。しかし、それを zend で使用するにはどうすればよいでしょうか。
indexcontroller の私のコードは
<?php
public function addAction()
{
$form = new UserForm();
$request = $this->getRequest();
if ($request->isPost())
{
$form->setData($request->getPost());
if($form->isValid())
{
$data=$form->getData();
$this->getUserTable()->insert($data);
}
}
}
public function getUserTable()
{
if(!$this->userTable)
{
$this->userTable = new TableGateway('eo_user',$this->getServiceLocator()->get('Zend\Db\Adapter\Adapter')
);
}
return $this->userTable;
}
eo_user テーブルのスキーマは
eo_user
user_id | username | user_password | user_email | user_status
ここで、user_id は自動インクリメント制約付きの主キーです。
挿入されたレコードの user_id を見つけるために必要な変更は何ですか?