Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [symfony] obsługa wyjątków
Papub
post
Post #1





Grupa: Zarejestrowani
Postów: 113
Pomógł: 1
Dołączył: 17.02.2006

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


witam, mam klasę
  1. class galeria_foldery {
  2. private $url;
  3. public function __construct($foldergalerii) {
  4. if(is_dir($foldergalerii)) {
  5. $this->url = $foldergalerii;
  6. } else {
  7. throw new Exception("Brak folderu galerii");
  8. }
  9. }
  10. }
  11.  
  12.  
  13. class galerieActions extends sfActions
  14. {
  15. try {
  16. $galeriafoldery = new galeria_foldery('galeriana');
  17. } catch(Exception $e) {
  18. $response['error'] = $e->getMessage();
  19. $this->status = json_encode($response);
  20. }
  21. }


Tworząc obiekt klasy galeria_foldery zgłasza wyjątek tak jak powinno być. Jednak $e-getMessage() zwraca mi null zamiast komunikatu błedu. Coś robię nie tak?

Ten post edytował Papub 22.04.2012, 17:18:19
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Papub
post
Post #2





Grupa: Zarejestrowani
Postów: 113
Pomógł: 1
Dołączył: 17.02.2006

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


  1. /*galeria zapisywana jest do bazy danych. Potem wyciągany jest jest id i tworzony katalog o takim id w folderze galeria. Przerzucamy tam pliki*/
  2. public function executeZapiszgalerie(sfWebRequest $request)
  3. {
  4. if($request->isXmlHttpRequest()) {
  5. $connection = Propel::getConnection();
  6. $connection->beginTransaction();
  7. $pokaznazwe = $this->getRequestParameter('pokaznazwe');
  8. $nazwa = $this->getRequestParameter('nazwa');
  9. $tytul = $this->getRequestParameter('tytul');
  10. $status = $this->getRequestParameter('status');
  11. $wyrownanie = $this->getRequestParameter('wyrownanie');
  12. $tytulyzdjec = $this->getRequestParameter('tytulyzdjec');
  13. $nazwyzdjec = $this->getRequestParameter('nazwyzdjec');
  14. $kolejnosc = $this->getRequestParameter('kolejnosc');
  15. $dostep = $this->getRequestParameter('dostep');
  16.  
  17. try {
  18. $c1= new Galerie();
  19. $c1->setNazwa($nazwa);
  20. $c1->setTytul($tytul);
  21. $c1->setAktywnosc($status);
  22. $c1->setDostep($dostep);
  23. $c1->setWyrownanie($wyrownanie);
  24. $c1->setPokaztytul($pokaznazwe);
  25. $c1->save($connection);
  26.  
  27.  
  28. /* wybranie id nowo dodanej galeri */
  29. $zapytanie = "SELECT max(i.id_galeri) as max FROM galerie i";
  30. $wykonaj = $connection->prepare($zapytanie);
  31. $wykonaj->execute();
  32. $resultset = $wykonaj->fetch(PDO::FETCH_OBJ);
  33. if($resultset->max) {
  34. $wynik = $resultset->max;
  35. } else {
  36. $wynik = 1;
  37. }
  38.  
  39.  
  40. /* dodanie zdjęć i tytułów zdjęć do bazy danych*/
  41. $sql = 'INSERT INTO galerie_zdjecia (tytul, id_galerii, nazwa, pozycja) VALUES (:tytul, :id_galerii, :nazwa, :pozycja)';
  42.  
  43. $statement = $connection->prepare($sql);
  44.  
  45. $count = 0;
  46. foreach ($nazwyzdjec as $key => $value) {
  47. $statement->bindValue(':tytul', $tytulyzdjec[$kolejnosc[$count]-1]);
  48. $statement->bindValue(':id_galerii', $wynik);
  49. $statement->bindValue(':nazwa', $value);
  50. $statement->bindValue(':pozycja', $count+1);
  51. $result = $statement->execute();
  52. $count++;
  53.  
  54. }
  55.  
  56. $connection->commit(); // zatwierdzenie
  57.  
  58. } catch (Exception $e) {
  59. $connection->rollback();
  60. $response['error'] = $e->getMessage();
  61. $this->status = json_encode($response);
  62. }
  63.  
  64. try {
  65. $galeriafoldery = new galeria_foldery('galeriana');
  66. } catch(Exception $e) {
  67. $response['error'] = $e->getMessage();
  68. $this->status = json_encode($response);
  69. }
  70. }
Go to the top of the page
+Quote Post

Posty w temacie


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: 14.10.2025 - 16:30