Здравствуйте. Есть код (необязательное уточнение). Хочу добавить страницу viewcity1.php и viewcity2.php - как мне это сделать? - вопрос №1344332

<?php
class Helpers_Document_Views{
protected $data=array();
private $pathFiles;

protected function __clone(){}
protected function __wakeup(){}

public function __construct(){
$this->setPathFiles();
}

public function __set($key,$value) {
$this->data[$key]=$value;
}

public function __get($key){
return (isset($this->data[$key])?$this->data[$key]:null);
}

public function __isset($key){
return isset($this->data[$key]);
}

public function assign($data){
foreach($data as $key=>$val){
$this->data[$key]=$val;
}
}

public function setPathFiles($path=''){
if($path==''){
$this->pathFiles=$_SERVER['DOCUMENT_ROOT'].'/';
}else{
$this->pathFiles=$path;
}
}

public function render($fileName,$type='code'){
$fileName=$this->pathFiles.$fileName;
if(is_file($fileName)){

ob_start();
if($type=='code'){

$c=file_get_contents($fileName);
if(trim($c)!=''){
if(!preg_match('{<!--compile-->}i',$c)){

$c=str_replace("'./","'/",$c);

$c='<!--compile-->'.$c;
file_put_contents($fileName,$c);
}
}

include $fileName;
}elseif($type=='text'){
echo file_get_contents($fileName);
}
return ob_get_clean();
}else{
return false;
}
}
}

class Models_Router
{
public function __construct($request=false){

if(!$request){
$request=$_REQUEST['page'];
}

$this->action($request);
}

protected function action($request){
if(trim($request)==''){

return false;
}

$data=explode('/',$request);

if(isset($data[0]) && trim($data[0])!=''){
$view=new Helpers_Document_Views;
$view->cityName=strtolower($data[0]);
$c=$view->render('viewCity.php');
$c=str_replace("'./","'/",$c);
$c=str_replace(«fancybox/»,"/fancybox/",$c);
die($c);

}

return false;
}
}

$router=new Models_Router;
?>
23.01.15
0 ответов
Ответов пока нет

Дима

Читать ответы

Павел Викторович

Читать ответы
Посмотреть всех экспертов из раздела Технологии > PHP
Пользуйтесь нашим приложением Доступно на Google Play Загрузите в App Store