Осваивая MVC паттерн столкнулся с тем, что не подгружаются у меня никакие файлы css в темплейте.
В чем может быть загвоздка?
Warning: require_once(app\controllers\cssController.php) [
function.require-once]: failed to open stream: No such file or directory in
Z:\home\localhost\www\namespace\app\lib\Autoloader.php on line
12Fatal error: require_once() [
function.require]: Failed opening required 'app\controllers\cssController.php' (include_path='.;C:\php\pear') in
Z:\home\localhost\www\namespace\app\lib\Autoloader.php on line
12
file - htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
file - Роутер
namespace app\lib;
use backEnd\Admin;
class Router {
static function route(){
$uri = explode('/',trim($_SERVER['REQUEST_URI'],'/'));
list($pfx,$controller,$action) = $uri;
if($controller === 'admin'){
new Admin();
}elseif(count($uri) == 1){
//echo 'route1';
$controller = 'Index';
}elseif(count($uri) <= 3){
//echo 'route2';
list($pfx,$controller,$action) = $uri;
}else{
//echo 'route3';
list($pfx,$controller,$action) = $uri;
for($i=3;$i< count($uri);$i++){
$params[] = $uri[$i];
}
}
$path = 'app\controllers\\'.$controller.'Controller';
new $path($controller,$action,$params);
}
}
file - autoloader
namespace app\lib;
class Autoloader {
static function autoload($className){
require_once $className.'.php';
}
}
spl_autoload_register('\app\lib\Autoloader::autoload');
file - Controller
<?php
namespace app\core;
use app\ErrorPages\P404;
use app\lib\_DB;
use app\lib\Template;
use app\lib\Test;
abstract class Controller {
protected $default = 'Index';
protected $controller;
protected $action;
protected $page;
protected $templater;
protected $params = array();
function __construct($controller,$action='',$params=''){
$this->session();
$this->controller = $controller;
$this->action = $action;
$this->params = $params;
$this->dispatch();
Test::testStart();
}
function dispatch(){
if(!isset($this->action)){
$method = $this->default.'Action';
$this->$method();
}else{
if(method_exists($this,$this->action.'Action')){
$method = $this->action.'Action';
$this->$method();
}else{
new P404();
}
}
}
function getTemplateName(){
$db = _DB::getInstance();
$flag_db = $db->dbconnect;
$prepared = $db->dbconnect->prepare("SELECT * FROM config");
$prepared->execute();
$prepared->setFetchMode($flag_db::FETCH_ASSOC);
$row = $prepared->fetch();
$path = APP_ROOT.'\\'.__NAMESPACE__.'\..\views\\'.$row['template'].'\\';
return $path;
}
function render(){
$this->page = $this->getTemplateName().'index.php';
$this->templater = new Template();
$this->buildPage();
$this->templater->display($this->page);
}
function buildPage(){
// echo '<pre>';
// var_dump($this->templater);
// echo '</pre>';
//$t = file_get_contents('<link href="'.'config\sys\css\system.css'.'" type="text/css">');
//return $this->templater->setVars(array('<t:header />' => $t,'<t:title />' => 'Title'));
}
abstract function IndexAction();
function ConnectModel(){
$modelName = $this->ModelFolder().$this->controller.'Model';
new $modelName();
}
function ModelFolder(){
return $path = APP_ROOT.'/app/models/';
}
function session(){
session_start();
$_SESSION['we'] = 'guest';
}
function __destruct(){
Test::testStop();
}
}
file - Templater
<?php
namespace app\lib;
class Template {
protected $arr = array();
protected $content;
function setVars($array=array()){
foreach($array as $find => $replace){
$this->arr[$find] = $replace;
}
}
function display($path){
$this->content = file_get_contents($path);
foreach($this->arr as $find => $replace){
$this->content = str_replace($find,$replace,$this->content);
}
echo $this->content;
}
}
file - index.php (template)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<t:header />
<t:title />
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
</body>
</html>