Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Własny framework pierwszy problem
Forum PHP.pl > Forum > PHP
rad11
Hej,

Z nudów chciałem sobie napisać jakiegoś swojego framework`a. I napotkałem na pierwszy problem przy próbie podania parametrów metody.
Tak więc:

  1. <?php
  2.  
  3. class Bootstrap {
  4.  
  5. private $url;
  6. private $moduleName;
  7. private $controllerName;
  8. private $methodName;
  9. private $parameters;
  10.  
  11. public function __construct() {
  12. require 'core/Config.php';
  13.  
  14. $this->url = isset($_GET['url']) ? $_GET['url'] : NULL;
  15. $this->url = rtrim($this->url, '/');
  16. $this->url = explode('/', $this->url);
  17.  
  18.  
  19. if (empty($this->url[0]) || empty($this->url[1]) || empty($this->url[2])) {
  20. header("Location: " . Config::$defaultController);
  21. }
  22.  
  23. $this->moduleName = $this->url[0];
  24. $this->controllerName = $this->url[1];
  25. $this->methodName = $this->url[2];
  26. $this->parameters = array_splice($this->url, 3);
  27.  
  28.  
  29. if (file_exists("application/$this->moduleName/controllers/$this->controllerName.php")) {
  30. require "application/$this->moduleName/controllers/$this->controllerName.php";
  31. } else {
  32. require 'core/errors.php';
  33. $error = new Errors();
  34. return false;
  35. }
  36.  
  37.  
  38. $controller = new $this->controllerName;
  39.  
  40. if (isset($this->parameters[0])) {
  41.  
  42. //nie wiem jak ten problem rozwiązać aby przekazać do metody tyle parametrów ile jest wpisanych w adresie?questionmark.gifquestionmark.gif
  43.  
  44. $controller->{$this->methodName}($this->parameters[0], $this->parameters[1], $this->parameters[2]);
  45. } else {
  46. if (isset($this->methodName)) {
  47. $controller->{$this->methodName}();
  48. }
  49. }
  50. }
  51.  
  52. }
  53.  


Jakies pomysły jak to można rozwiązać?

Ok mam sprawe załatwiło:

  1. call_user_method_array($this->methodName, $controller, $this->parameters);
Tomplus
Nie wiem w jak te parametry przenosisz, ale zmienna globalna _SERVER posiada takie dane, a można łatwo je odczytać dzięki: http://php.net/manual/en/function.parse-url.php
rad11
O dzięki też się przyda taka informacja.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.