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:
<?php
class Bootstrap {
private $url;
private $moduleName;
private $controllerName;
private $methodName;
private $parameters;
public function __construct() {
require 'core/Config.php';
$this->url = isset($_GET['url']) ?
$_GET['url'] : NULL; $this->url = rtrim($this->url, '/'); $this->url = explode('/', $this->url);
if (empty($this->url[0
]) || empty($this->url[1
]) || empty($this->url[2
])) { header("Location: " . Config
::$defaultController); }
$this->moduleName = $this->url[0];
$this->controllerName = $this->url[1];
$this->methodName = $this->url[2];
if (file_exists("application/$this->moduleName/controllers/$this->controllerName.php")) { require "application/$this->moduleName/controllers/$this->controllerName.php";
} else {
require 'core/errors.php';
$error = new Errors();
return false;
}
$controller = new $this->controllerName;
if (isset($this->parameters[0])) {
$controller->{$this->methodName}($this->parameters[0], $this->parameters[1], $this->parameters[2]);
} else {
if (isset($this->methodName)) { $controller->{$this->methodName}();
}
}
}
}
Jakies pomysły jak to można rozwiązać?
Ok mam sprawe załatwiło:
call_user_method_array($this->methodName, $controller, $this->parameters);
Ten post edytował rad11 31.10.2015, 11:22:53