Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Tworzenie obiektu poprzez podanie nazwy klasy w zmiennej string
Pronigo
post
Post #1





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 8.05.2005
Skąd: Gdańsk

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


Witam,
mam taki kodzik:

  1. <?php
  2. include 'system/libraries/actionController.class.php';
  3. include 'application/controllers/'.$_GET['module'].'ActionController.class.php';
  4.  
  5. $class = $_GET['module'] . 'ActionController';
  6.  
  7. $controller = new $class;
  8. $controller->indexAction();
  9. ?>


Chyba wiecie o co mi chodzi. Chcę zrobić w przerobić swój framework na wzorcu MVC, ale nie wiem jak wybierać odpowiednią klasę i funkcję przez dane przekazane w zmiennej $_GET['module']. Ten kto zna popularne frameworki na pewno zrozumie o co mi chodzi (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Dzięki

Ten post edytował Pronigo 24.05.2008, 22:15:43
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Landon
post
Post #2





Grupa: Zarejestrowani
Postów: 83
Pomógł: 3
Dołączył: 21.04.2007
Skąd: Sosnowiec

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


a może by tak poczytać inne tematy np:

  1. <?
  2. class Kernel {
  3.  
  4. public $classList = array();
  5. public $dir;
  6.  
  7. public function __construct($dir = './') {
  8. if (!$this -> classList['Karnel']) {
  9. $this -> dir = $dir;
  10. $this -> classList['Karnel'] = true;
  11. }
  12. }
  13.  
  14. public function __call($method, $args) {
  15. return Debug::error('Nie istnieje funckja '.$method, 'Karnel');
  16. }
  17.  
  18. public function load($className, $parametr = false, $new = false) {
  19. if (!in_array($className, $this -> classList, true)) {
  20. if (file_exists($this -> dir.'class/'.$className.'.class.php')) 
  21. require_once('class/'.$className.'.class.php');
  22. elseif (file_exists($this -> dir.'lib/'.$className.'/'.$className.'.class.php')) 
  23. require_once('lib/'.$className.'/'.$className.'.class.php');
  24. else return Debug::error('Nie ma takiej biblioteki', 'Karnel');
  25. // tu dajesz swoje katalogi zamiast moich
  26. if ($new) $this -> classList[$className] = ($parametr) ? new $className($parametr) : new $className;
  27. else $this -> classList[$className] = true;
  28. return $this -> classList[$className];
  29. } else return Debug::error('2 deklaracja tej samej biblioteki', 'Karnel');
  30. }
  31.  
  32. }
  33. ?>


Ten post edytował Landon 25.05.2008, 22:00:52
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: 5.10.2025 - 12:28