Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramework][ZF2][ZendFramework2] mysql łączenie tabel używając TableGateway
umatik
post
Post #1





Grupa: Zarejestrowani
Postów: 209
Pomógł: 0
Dołączył: 17.05.2002
Skąd: lodz

Ostrzeżenie: (0%)
-----


W Modue.php mam zdeklarowaną fabrykę:
  1. 'HistoryTable' => function($sm)
  2. {
  3. $tableGateway = $sm->get('HistoryTableGateway');
  4. $table = new HistoryTable($tableGateway);
  5. return $table;
  6. },
  7. 'HistoryTableGateway' => function ($sm)
  8. {
  9. $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
  10. $resultSetPrototype = new ResultSet();
  11. $resultSetPrototype->setArrayObjectPrototype(new History());
  12. return new TableGateway('cases_log', $dbAdapter, null, $resultSetPrototype);
  13. },


Chciałbym za pomocą HistoryTableGateway pobrać z bazy danych informację z 2 tabel:
  1. SELECT L.id AS 'l_id', L.date, L.action, U.id AS 'u_id', U.name, U.surname
  2. FROM cases_log L, users U
  3. WHERE L.user = U.id
  4. LIMIT 0,30


Póki co udało mi się pobrać dane za pomocą join, tylko że pobiera dane z jednej tablicy:
  1. SELECT * FROM `cases_log`
  2. JOIN users
  3. ON users.id = cases_log.user


Funkcja pobierająca dane w HistoryTable.php:
  1. $table = $this->tableGateway;
  2. $select = $table->getSql()->select();
  3. //$select->from(array('L' => 'cases_log'))->join(array('U' => 'users'),'L.user = U.id');
  4. //$select->columns(array('action', 'surname'));
  5. $select->join('users', 'users.id = cases_log.user');
  6.  
  7. $select->limit(10);
  8. $select->offset(0);
  9. $resultSet = $table->selectWith($select);
  10.  
  11. return $resultSet;

Jak widać w zakomentowanych liniach próbowałem dostać się jakoś do sekcji SELECT - niestety konstrukcja HistoryTableGateway ustawia $select->from na read only ...
Da się to w ten sposób zrobić ?

Ten post edytował umatik 13.05.2015, 10:10:47
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 20:17