Ответов: 3 Просмотров: 1316
|
Помогите с сайтом.Обучаюсь по курсу OOP PHP mvc,но когда нужно выводить шаблон сайта на экран,то он не выводится.Хотя должна отработать public function get_page(){
echo $this->page;,а на экране ничего чистый экран.Что это может быть?
Вот код базового контрооллера
PHP:
скопировать код в буфер обмена
<?PHP abstract class Base_Controller { //свойства protected $request_url; protected $controller; protected $params; protected $styles,$styles_admin; protected $scripts,$scripts_admin; protected $error; protected $page; //Методы public function route(){ $ref = new ReflectionClass($this->controller); if($ref->hasMethod('request')){ if($ref->isInstantiable()){ $class = $ref->newInstance(); $method = $ref->getMethod('request'); $method->invoke($class,$this->get_params()); } } } else{ throw new ContrException('Такой страницы не существует'); } } public function init(){ global $conf; if(isset($conf['styles'])){ foreach($conf['styles'] as $style){ $this->styles[] = trim($style,'/'); } } if(isset($conf['styles_amin'])){ foreach($conf['styles_admin'] as $style_admin){ $this->styles_admin[] = trim($style_admin,'/'); } } if(isset($conf['scripts'])){ foreach($conf['scripts'] as $script){ $this->scripts[] = trim($script,'/'); } } if(isset($conf['scripts_amin'])){ foreach($conf['scripts_admin'] as $script_admin){ $this->scripts_admin[] = trim($script_admin,'/'); } } } protected function get_controller(){ return $this->controller; } protected function get_params(){ return $this->params; } protected function input(){ } protected function output(){ } public function request ($param = array()){ $this->init(); $this->input($param); $this->output(); if(!empty($this->error)){ $this->write_error($this->error); } $this->get_page(); } public function get_page(){ echo $this->page; } protected function render ($path,$param = array()){ if(!include($path.'.php')){ throw new ContrException('Данного шаблона не существует.'); } } public function clear_str($var){ foreach($var as $key => $item){ } return $row; } } public function clear_int($var){ return (int)$var; } public function is_post(){ if($_SERVER['REQUEST_METHOD'] == 'POST'){ return TRUE; } return FALSE; } public function check_auth(){ } public function write_error($err){ $time = date("d-m-Y G:i:s"); $str = "Fault: ".$time." - ".$err."\n\r"; } public function img_resize($dest){ } } ?>
|