php控制器没有加载css文件

时间:2017-10-22 21:08:10

标签: javascript php html

我正在使用我自己的MVC php工作,我从控制器和从url调用的方法,它调用正确的控制器和正确的方法,但它没有加载css和javascript代码。

例如,当我去mysite / public / home / index时 它调用控制器home和方法索引。但它试图从mysite / public / home / css / mystyle.css加载css,我的css在mysite / public / css / mystyle.css

这是我的目录 Directory Picture

// this is my index.php in the public folder

<?php

require_once "../app/init.php";
$app = new app();

//this is my app class in core
class app
{
    protected $controller = 'home';
    protected $method = 'index';
    protected $params = [];

    public function __construct()
    {
        $url = $this->parseUrl();
        if (file_exists('../app/controllers/' . $url[0] . '.php')) {
            $this->controller = $url[0];
            unset($url[0]);
            echo $this->controller . "/";
        }
        require_once '../app/controllers/' . $this->controller . '.php';
        $this->controller = new $this->controller();
        if (isset($url[1])) {
            if (method_exists($this->controller, $url[1])) {
                $this->method = $url[1];
                unset($url[1]);
            } else {
                echo $this->method;
                unset($url[1]);
            }
        }
        $this->params = $url ? array_values($url) : [];
        call_user_func([$this->controller, $this->method], $this->params);
    }

    public function parseUrl()
    {
        if (isset($_GET['url'])) {
            return explode('/', filter_var(rtrim($_GET['url'], "/"),
                FILTER_SANITIZE_URL));
        }
    }
}

//this is my class controller in core
class Controllers
{
    public function view($page)
    {
        require_once '../app/views/' . $page . '.php';
    }

    public function model($model)
    {
        require_once '../app/models/' . $model . '.php';
    }
}

//this is my controller home
class Home extends Controllers
{
    public static function index()
    {
        $this->view('home');
    }


}
//this is the code where I embed the css/jss it's located in the view called home

<head>
<meta charset="UTF-8">
<title>ChatMe-Home</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
</head>
//this is the htaccess file
Options -MultiViews
RewriteEngine On
RewriteBase /facebook/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

1 个答案:

答案 0 :(得分:0)

尝试

{{1}}