Có một khả năng khác để thêm FeatureSet vào TableGateway.
Trong Module.php bạn có thể xác định (bảng tài khoản ví dụ)
'UserTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new UserEntity());
return new TableGateway('user', $dbAdapter, new Feature\SequenceFeature('user','user_id_seq'), $resultSetPrototype);
Nhưng có một lỗi trong SequenceFeature. Mọi thứ đều ổn, khi bạn sử dụng lược đồ công khai. Khi bạn phải sử dụng lược đồ khác, bạn nên sử dụng Zend \ Db \ Sql \ TableIdentifier;
Trong trường hợp này là Mô-đun.php nên là:
'UserTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new UserEntity());
return new TableGateway(new TableIdentifier('user','someSchema'), $dbAdapter, new Feature\SequenceFeature(new TableIdentifier('user','someSchema'),'user_id_seq'), $resultSetPrototype);
Trong trường hợp này sẽ là một lỗi với PostgreSQL truy vấn SELECT NEXTVAL, bởi vì tính năng \ SequenceFeature sẽ sử dụng sơ đồ công cộng thay vì quy định tại đối số đầu tiên để chuẩn bị truy vấn
CHỌN NEXTVAL ('user_id_seq ')
Trong trường hợp này truy vấn sql nên
CHỌN NEXTVAL (' someSchema'. 'user_id_seq')
Nguồn
2016-12-14 14:06:01
Hãy thử '$ this-> tableGateway-> getAdap ter() -> lastInsertId(); ' – phpisuber01
Lỗi nghiêm trọng: Gọi đến phương thức chưa xác định Zend \ Db \ Adapter \ Adapter :: lastInsertId() – Piotr
Hmmm ...' $ this-> lastInsertValue; 'hoặc' $ this-> tableGateway -> lastInsertValue; 'Điều duy nhất tôi có thể nghĩ đến. – phpisuber01