Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Własny framework pierwszy problem
rad11
post
Post #1





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


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?(IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/questionmark.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);


Ten post edytował rad11 31.10.2015, 11:22:53
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: 6.10.2025 - 21:10