문제

I'm developing web application with Zend Framework. In the documentation it says ...

"Be aware though that the Table Data Gateway pattern can become limiting in larger systems."

  • What are the drawbacks of using Table Data Gateway ?
  • What is the most suitable way to handle database with Zend ?
도움이 되었습니까?

해결책

Drawbacks of using Table Data Gateway is that it can limit you from writing complex queries. Custom queries such as UNION, SUB QUERY and also using WHERE clauses such as

 WHERE A OR (B AND C) OR D

Best way to write complex queries is to write the complex query by hand. So the best way to execute them is using the Zend_Db_Adapter

다른 팁

In ZF2 there was such thing like Data Mapper (you can see this answer: What is the difference between the Data Mapper, Table Data Gateway (Gateway), Data Access Object (DAO) and Repository patterns?

But if You are using ZF2 this problem has bees solved and the most efficient way to communicate with database is TableGateway with defined ResultSetPrototype (as one of models with exchangeArray function) and ofc trough Zend/Db/Adapter class here is sample how i do it in ZF2:

IN SERVICE.CONFIG:

'Gallery\Model\AnythingListTable' =>  function($sm) {
        $tableGateway = $sm->get('AnythingListTableGateway');
        $table = new AnythingListTable($tableGateway);
        return $table;
    },
    'AnythingListTableGateway' => function ($sm) {
        $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
        $resultSetPrototype = new ResultSet();
        $resultSetPrototype->setArrayObjectPrototype(new Anything());
        return new TableGateway('Anything', $dbAdapter, null, $resultSetPrototype);
    },

AnythingTable is one model (with functions to manipulate database) Anything is second model with filters and rules about data form DB

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top