我想加載一個JavaScript和CSS文件的鏈接和腳本標籤。該項目使用php命名空間,因此文件正嘗試通過設置控制器的路由器腳本加載。也許需要更多的解釋。PHP命名空間加載JavaScript文件錯誤
當訪問者第一次來到http://site0
根.htaccess
文件重寫到/public
目錄與文件/public/.htaccess
一切改寫爲/public/index.php
文件。 /public/index.php
只是一個spl_autoload
函數,並調用router.class.php
腳本來決定調用哪個控制器類。
的root .htaccess
內容:的public/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
#RewriteCond %{REQUEST_URI} \.css$
RewriteRule (styles/[^/]+\.css)$ /$1 [L]
# File is located in /foldername/images/
# Internal redirect. Does not change address in the browsers address bar.
RewriteCond %{REQUEST_URI} \.(gif|jpg|png)$
RewriteRule ^.*(images)/(.*)(\.gif|jpg|png)$ $1/$2$3 [L]
# File is located in /foldername/scripts/.
# Internal redirect. Does not change address in the browsers address bar.
RewriteCond %{REQUEST_URI} \.js$
RewriteRule (scripts/[^/]+\.js)$ /$1 [L]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
內容:中public/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
內容:
<?
//set_include_path('PATH_TO_GLOBAL_LIBS; PATH_TO_LIBRARY_1; PATH_TO_LIBRARY_X; PATH_TO_DOCUMENT_ROOT');
define('DS', DIRECTORY_SEPARATOR);
define ('ROOT', dirname(dirname(__FILE__)));
include_once (ROOT . DS . 'inc/dbconf.php');
function multi_autoloader($class)
{
$class = preg_replace('/^((\w*)\\\){2}/', '', $class);
$file = ROOT . DS . str_replace('\\', DS, strtolower($class)) . '.class.php';
if (file_exists($file))
{
require ($file);
}
}
spl_autoload_register('multi_autoloader');
use potts\john\libs\router\Router as Router;
$router = Router::getInstance();
$router->initRouter();
的router.class.php
文件是相當大的,但如果你需要看它, 讓我知道。通過console/inspector
我從css和javascript文件中獲得狀態500
。在一個我不需要使用php namspaces的項目中,所有的工作都很好。所以這必須是由空隙造成的問題。
有關如何解決此問題的任何建議?