Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Zend] Last inserted ID z create row
reyne
post 14.01.2011, 15:51:53
Post #1





Grupa: Zarejestrowani
Postów: 73
Pomógł: 1
Dołączył: 19.12.2007

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


Witam, mam taki kawałek kodu (z Social Engine 4 opartym na Zendzie), który tworzy wydarzenie i dodaje również temat z taką samą nazwą na forum:

  1. // Process
  2. $values = $form->getValues();
  3. $values['user_id'] = $viewer->getIdentity();
  4. $values['parent_type'] = $parent_type;
  5. $values['parent_id'] = $parent_id;
  6. if( $parent_type == 'group' && Engine_Api::_()->hasItemType('group') && empty($values['host']) ) {
  7. $values['host'] = $group->getTitle();
  8. }
  9.  
  10. $db = Engine_Api::_()->getDbtable('events', 'event')->getAdapter();
  11.  
  12.  
  13. $db->beginTransaction();
  14.  
  15. try
  16. {
  17. // Create event
  18. $table = $this->_helper->api()->getDbtable('events', 'event');
  19. $event = $table->createRow();
  20. $lastid = $this->table->getAdapter()->lastInsertId();
  21.  
  22. $event->setFromArray($values);
  23. $event->save();
  24.  
  25. $data = array(
  26. 'forum_event_id' => '',
  27. 'topic_id' => '7',
  28. 'event_id' => ''.$lastid.''
  29. );
  30.  
  31. $db->insert('engine4_forum_event_topics',$data);


Sprawa wydaję się prosta bo wystarczy użyć funkcji lastInsertId();
Jednak nie działa - zmienna lastid nie przekazuje ostatnio dodanego rekordu do bazy, bo źle to wstawiam i nie wiem gdzie to powinno być.

Mam taki błąd:

  1. Call to a member function getAdapter() on a non-object


Jak wstawić i "wychwycić" ostatnio dodane ID eventu z bazy poprawnie?
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 09:22