SergXP
Новичок
Всем доброе время суток!
Помогите разобраться с проблемой передачи объекта класса..
Пытаюсь сделать так, чтобы работал вывозов в контроллере:
вот что у меня получается
пробовал через статические методы, передачу через конструктор при вызове контроллера..
Подскажите, в чем проблема?
Спасибо
Помогите разобраться с проблемой передачи объекта класса..
Пытаюсь сделать так, чтобы работал вывозов в контроллере:
PHP:
$router = $this->getRouter();
echo $router->url($name);
//тоже самое
$this->getRouter()->url($name);
PHP:
class router {
public $urls = array('signup'=>'/signup');
function __construct() {
$this->urls['login'] = '/login';
}
function exucete() {
$action = 'index';
$controller = 'index';
$controller = new $controller();
$controller->$action();
}
public function getInstance() {
return $this;
}
public function url($name) {
echo $this->urls[$name];
}
}
class controller {
function __construct() {
}
function getRouter() {
return router::getInstance();
}
}
class index extends controller {
public $controller = 'index';
function index() {
print_r($this->getRouter()); // в итоге выводит массив контроллера, а не роутера
$this->getRouter()->url();
}
}
$router = new router;
$router->exucete();
Подскажите, в чем проблема?
Спасибо