私は自分のMVC PHPでプロジェクトに取り掛かりました。私はコントローラとメソッドをURLから呼び出すようにしました。これは正しいコントローラと適切なメソッドを呼び出しますが、 cssとjavascriptコードを読み込みません。PHPコントローラがCSSファイルをロードしません
たとえば、mysite/public/home/index に行くと、コントローラーのホームとメソッドのインデックスが呼び出されます。しかし、それは個人用サイト/公共/ホーム/ CSS/mystyle.cssからCSSをロードしようと私のCSSは、個人用サイトにある/公共/ 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]
で試してみてください、テストコードを助けるかの答えに使用するためにコピー&ペーストすることができませんスクリーンリーダーを使用するユーザーには敵対的です。質問を編集して、質問の本文にコードを追加することができます。 '{}'ボタンを使ってコードのブロックを整形するか、同じ効果のために4つのスペースをインデントします。スクリーンショットをコードとして実行することはできません。 – tadman
あなたのコードを投稿してください –
こんにちは!私はちょうどそれを投稿する –