Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> php 5.3 router
aras785
post
Post #1





Grupa: Zarejestrowani
Postów: 859
Pomógł: 177
Dołączył: 29.10.2009

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


Witam. Uczę się php 5.3 i przerabiam MVC, który ostatnio napisałem (wrzuciłem na forum) i mam pytanie dotyczące use i namespace.
Jak sprawdzić czy klasa istnieje? Mam to ogarnąc przez: spl_autoload_register i tam zrobić np. przekierowanie do strony z bledem?
To co niżej podałem to nwywala wyjątek z spl...
  1. <?php
  2. namespace Lib;
  3. class Router {
  4. //private $controller;
  5. //private $action;
  6. public function __construct(Request $request) {
  7. //$this->controller = $request->getController();
  8. //$this->action = $request->getAction();
  9. if($class = new \Application\Controller\Index) {
  10.  
  11. }
  12.  
  13. }
  14. }


Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sazian
post
Post #2





Grupa: Zarejestrowani
Postów: 1 045
Pomógł: 141
Dołączył: 19.09.2006
Skąd: B-tów

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


  1. function ClassLoader($classname)
  2. {
  3. $file=$classname.'.php';
  4. if(file_exists($file) && is_readable($file))
  5. {
  6. require_once($file);
  7. if(class_exists($classname, false))
  8. {
  9. return true;
  10. }
  11. }
  12. return false;
  13. }
  14.  
  15. spl_autoload_register('ClassLoader');
  16.  
  17.  
Go to the top of the page
+Quote Post

Posty w temacie
- aras785   php 5.3 router   23.02.2013, 15:39:22
- - Crozin   class_exists?   23.02.2013, 15:41:05
- - aras785   Nie o to chodzi. Jeśli klasa nie istnieje to wywal...   23.02.2013, 16:14:17
- - sazian   [PHP] pobierz, plaintext function ClassLoader...   26.02.2013, 20:31:02


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: 10.10.2025 - 09:39