Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZF]Dynamicznie tworzony warunek dla filtrowania rekordów
amii
post
Post #1





Grupa: Zarejestrowani
Postów: 728
Pomógł: 76
Dołączył: 12.06.2009

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


Mam metodę w klasie rekordu, która filtruje skojarzone rekordy:

  1. class Application_Model_DbTable_Trainings_Row extends Zend_Db_Table_Row
  2. {
  3. public function getInstance($cond = NULL, $cond2 = NULL) {
  4. if ($cond !== NULL) {
  5. $m = new Application_Model_DbTable_TrainingInstance();
  6. $s = $m->select()->where($cond, $cond2)->order('date_start ASC');
  7. return $this->findDependentRowset('Application_Model_DbTable_TrainingInstance', null, $s);
  8. }
  9. return $this->findDependentRowset('Application_Model_DbTable_TrainingInstance');
  10. }
  11.  
  12. }
  13.  
  14. //przykladowe wywolanie, gdzie $v1 to pojedynczy rekord z tabeli Application_Model_DbTable_Trainings
  15. $v1->getInstance('date_start > ?', new Zend_Db_Expr('CURDATE()'));


To działa ale dla pojedynczego warunku a co jeśli chce przesłać klika warunków w tabeli ? Przydała by się taka dynamiczność bo teraz dla zapytań filtrujących różną ilość warunków muszę tworzyć osobne metody w klasie Application_Model_DbTable_Trainings_Row
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
k_@_m_i_l
post
Post #2





Grupa: Zarejestrowani
Postów: 349
Pomógł: 72
Dołączył: 22.01.2008
Skąd: Wadowice/Oświęcim

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


Spóbuj coś takiego
  1. class Application_Model_DbTable_Trainings_Row extends Zend_Db_Table_Row
  2. {
  3. public function getInstance($conds) {
  4. if (count($conds)) {
  5. $m = new Application_Model_DbTable_TrainingInstance();
  6. $select = $m->select();
  7. foreach($conds as $where)
  8. {
  9. $select->where($where['condition'],$where['value']);
  10. }
  11. return $this->findDependentRowset('Application_Model_DbTable_TrainingInstance', null, $s);
  12. }
  13. return $this->findDependentRowset('Application_Model_DbTable_TrainingInstance');
  14. }
  15.  
  16. }
  17.  
  18. //przykladowe wywolanie, gdzie $v1 to pojedynczy rekord z tabeli Application_Model_DbTable_Trainings
  19. $v1->getInstance(array(
  20. array('condition'=>'id > ?','value'=>array(1)),
  21. array('condition'=>'id < ?','value'=>array(5))
  22. ));


Ten post edytował k_@_m_i_l 12.12.2012, 15:20:55
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: 23.08.2025 - 18:12