Как подгружать внешние css файлы в MVC архитектуре?

Осваивая 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 12



Fatal 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>
  • Вопрос задан
  • 2705 просмотров
Пригласить эксперта
Ответы на вопрос 2
0neS
@0neS
Я не увидел, в каком месте происходит require_once(app\controllers\cssController.php)?
Ответ написан
@whiteleaf Автор вопроса
Сразу хотел бы извиниться за мой начинающий код... :)

Этот require_once запускается с Autoloader.php. Я использую namespac'сы для автоподгрузки класссов.
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 12
При загрузке классов проблем не было, а здесь почему,то ошибка...
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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