Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Kohana] Dodawanie i edycja danych z relacjami
in5ane
post
Post #1





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Cześć, mam kłopot z edycją danych. Zapis nowych danych działa poprawnie, a podczas edycji danych zamiast je edytować z tabeli relatywnej, to dodaje nowy wpis, jak temu zaradzić? Chodzi o te newsTexts. Relacje działają na pewno poprawnie, bo pobieranie działa dobrze. Domyślam się również, że może edycji nie da się w taki sposób, tylko trzeba normalnie operować na konkretnej tabeli. Mój kod poniżej.

  1. if ($id)
  2. {
  3. $news = ORM::factory('New', $id);
  4. }
  5. else
  6. {
  7. $news = ORM::factory('New');
  8. $news->date = time();
  9. }
  10. if (!empty($_FILES['img']['name']))
  11. {
  12. if ($id)
  13. {
  14. $file = $news->img;
  15. $directory = 'assets/files/news/';
  16. if (file_exists($directory . $file))
  17. {
  18. unlink($directory . $file);
  19. }
  20. }
  21. $news->img = $this->_saveImage($_FILES['img']);
  22. }
  23. $news->save();
  24.  
  25. $newsTexts = $news->texts;
  26. $newsTexts->news_id = $news->id;
  27. $newsTexts->lang_id = 1;
  28. $newsTexts->title = $this->request->post('titleSv');
  29. $newsTexts->short_content = $this->request->post('shortContentSv');
  30. $newsTexts->content = $this->request->post('contentSv');
  31. $newsTexts->save();
  32.  
  33. $newsTexts = $news->texts;
  34. $newsTexts->news_id = $news->id;
  35. $newsTexts->lang_id = 2;
  36. $newsTexts->title = $this->request->post('titleEn');
  37. $newsTexts->short_content = $this->request->post('shortContentEn');
  38. $newsTexts->content = $this->request->post('contentEn');
  39. $newsTexts->save();


Ten post edytował in5ane 2.04.2014, 18:47:49


--------------------
> > > Tworzenie stron < < <
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 Aktualny czas: 21.08.2025 - 16:17