[英]Alternative to TableGateway for Zend Framework 2
I'm using Zend framework 2 to create web pages. 我正在使用Zend Framework 2创建网页。
Through TableGateway I'm accessing my PostgreSQL DB . 通过TableGateway,我正在访问PostgreSQL 数据库 。
Is there any alternative to TableGateway that can be used effectively in Zend framework 2 , with easy-to-use documentation and stuff? 除了TableGateway之外 ,还有其他替代方法可以通过易于使用的文档和内容在Zend Framework 2中有效使用吗?
I'm trying to get away from Doctrine 2 ( unless you could convince me otherwise ). 我正试图摆脱“学说2” ( 除非您可以使我信服 )。
Any help would be appretiated. 任何帮助将不胜感激。
As I commented, I used 3 ways to handle data access. 正如我所评论的,我使用3种方式来处理数据访问。
TableGateway patter is ok but it's not easy to maintain for larger applications. TableGateway的模式还可以,但对于大型应用程序而言,维护起来并不容易。
Another commonly used pattern is the data mapper pattern, for this you can use AbstractDbMapper and hydrator for mapping. 另一个常用的模式是数据映射器模式,为此,您可以使用AbstractDbMapper和水化器进行映射。 AbstracDbMapper Link AbstracDbMapper链接
I finally decided to use doctrine basically cause is very easy to maintain and you can save some hours of code, but if you don't want to use doctrine i think that Data Mapper Pattern is the best option. 我最终决定使用该原则,基本上很容易维护,并且可以节省一些时间的代码,但是如果您不想使用该原则,我认为Data Mapper Pattern是最好的选择。
What is really confusing? 真正令人困惑的是什么? If you are using Zend MVC, Then Service Manager/Locator is using every where and that is way to define TableGateway/DB Models too. 如果您使用的是Zend MVC,那么Service Manager / Locator会使用所有位置,这也是定义TableGateway / DB模型的一种方式。 Model's code still good and understanding. 模型的代码仍然很好并且理解。 I don't understand where is really confusing. 我不明白真正令人困惑的地方。
One change I can suggest the original ZF 2.0 style simpler getServiceConfig which is working for me till now. 我可以建议采用一种ZF 2.0风格的简单的getServiceConfig,这是迄今为止对我有用的更改。
'Album\Model\AlbumTable' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new Model\AlbumTable($dbAdapter);
return $table;
},
Instead of 代替
'Album\Model\AlbumTable' => function($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
I did not faced any problem by using previous one but can't say if others faced ? 通过使用上一个我没有遇到任何问题,但是不能说其他人是否遇到了?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.