所以在我的应用程序中,假设{{3}}这是一个URL。 所以在这个url用户是我的控制器,登录是用户控制器中的方法,这是在我的核心文件中编码,如下所示:
<?php
/**
*
*/
class Bootstrap
{
function __construct()
{
$url = isset($_GET['url'])?$_GET['url']:null;
$url = rtrim($url,'/');
$url = explode('/', $url);
//print_r($url);
if (empty($url[0])) {
require 'controllers/welcome.php';
$controller = new Welcome();
$controller->index();
return false;
}
$file = 'controllers/'.$url[0].'.php';
if (file_exists($file)) {
require $file;
} else {
$this->showError();
}
$controller = new $url[0];
//calling methods
if (isset($url[2])) {
if (method_exists($controller, $url[2])) {
$controller->{$url[1]}($url[2]);
} else {
$this->showError();
}
} else {
if(isset($url[1])){
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}();
} else {
$this->showError();
}
} else {
$controller->index();
}
}
}
public function showError() {
require 'controllers/CustomError.php';
$controller = new CustomError();
$controller->index();
return false;
}
}
现在我的问题是当我尝试在视图中加载css文件时,我的URL变成这样:
http://localhost:8888/mvc/public/css/style.css
所以现在根据上面的代码,假设public是一个控制器而CSS是一个方法。它给出了一个错误。 那我怎么解决这个问题呢?
我希望你们明白这是什么问题。 感谢。
答案 0 :(得分:1)
在视图的head部分中尝试以下CSS文件:
<link rel="stylesheet" type="text/css" href="http://localhost:8888/mvc/public/css/style.css">