@grigorie1990

(пишу фреймворк) почему браузер выдает ошибку страница не найдена?

Здравствуйте,
Пишу небольшой фреймворк(по видеокурсу). Когда пытаюсь перейти на uri '/page/test' браузер не находит страницы, хотя должен выводить на экране надпись. Может дело в регулярных выражениях в файле "urls.php"?

<?php

	class griEngine {

	public
		$settings, //settings
		$uri,  //current URI
		$app;  //curent app

	public function __construct($settings) {

		$this->settings= $settings;
		$this->uri = urldecode(preg_replace('/\?.*/iu','',$_SERVER['REQUEST_URI']));
		$this->app = false;
		$this->process_path();
		$this->process_controllers();
		
	}
	
	public function process_path() {
				
		foreach( $this->settings['apps'] as $iterable_app )
		{
			$iterable_urls = require(BASE_DIR. '/apps/'. $iterable_app. '/urls.php');
			foreach( $iterable_urls as $pattern => $method)
			{
				$matches = array();
				if (preg_match($pattern, $this->uri, $matches))
				{
					
					$this->app = array($iterable_app, array('pattern' => $pattern, 'method' => $method, 'args' => $matches));
					break(2);
					
				
		}

		if( $this->app ==='false')
		{
			exit('App not found.');
		}
	}

	public function process_controllers() {

		if ($this->app || is_array($this->app))
		{
			require(BASE_DIR.'/apps/'.$this->app['0'].'/controller.php');
			$controller_name = $this->app['0'].'_Controller';
			$this->app_controller = new $controller_name();
			$this->app_controller->{$this->app['1']['method']}($this->app['1']['args']);
		} 
	}


	}


---------------------------
файл urls.php
<?php

	return array(

	'#^/*$#i' => 'MainPage',
	'#^/Page/([A-z0-9_-])/*#i' => 'ViewPage'

	);

---------------------
файл controller.php
<?php


	class Simple_Pages_Controller extends gri_Controller {

	public function MainPage($args){
		echo 'Hello world';
	}


	public function ViewPage(){
		echo 'test';
	}
	}
	?>
  • Вопрос задан
  • 125 просмотров
Пригласить эксперта
Ответы на вопрос 1
ThunderCat
@ThunderCat Куратор тега PHP
{PHP, MySql, HTML, JS, CSS} developer
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы