php命名空间加载javascript文件错误

php命名空间加载javascript文件错误,php,.htaccess,Php,.htaccess,我正在尝试加载带有链接和脚本标记的javascript和css文件。该项目使用php名称空间,因此文件试图通过设置控制器的路由器脚本加载。也许需要更多的解释 当访客第一次来到http://site0根.htaccess文件用/public/.htaccess文件重写到/public目录。htaccess文件将所有内容重写到/public/index.php文件。/public/index.php只是一个spl\u autoload函数,它调用router.class.php脚本,该脚本决定调用哪

我正在尝试加载带有链接和脚本标记的javascript和css文件。该项目使用php名称空间,因此文件试图通过设置控制器的路由器脚本加载。也许需要更多的解释

当访客第一次来到
http://site0
.htaccess
文件用
/public/.htaccess
文件重写到
/public
目录。htaccess文件将所有内容重写到
/public/index.php
文件。
/public/index.php
只是一个
spl\u autoload
函数,它调用
router.class.php
脚本,该脚本决定调用哪个控制器类

root.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的内容

 <?
 //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();

这是一个丑陋的黑客行为,但它确实有效:

/**
 * Sets the appropriate controller
 * 
 * 
 * @return object $this->controller
 */ 

private function setController() 
{

   $this->_seo_uri = $this->seoUrl();

   $this->__controller = array_shift($this->_seo_uri);

        if ($this->__controller == 'styles')
        {
               /* dev purposes only. php will return error that gets 
                  appended to end of file.
                */
          ini_set('display_errors',0);

          /* include will return file with mime type 'text/html 
             thus not interpreting file as stylesheet
           */
           header('Content-type: text/css');  

           // readfile works too. your choice...   
           //readfile($_SERVER['DOCUMENT_ROOT']. '/styles/style.css');

             include ($_SERVER['DOCUMENT_ROOT']. '/styles/style.css'); 


        }
        elseif ($this->__controller == 'scripts')
        {
               /* dev purposes only. php will return error that gets 
                  appended to end of file.
               */
          ini_set('display_errors',0); 

             include ($_SERVER['DOCUMENT_ROOT']. '/scripts/gui.js');


        }
        else 
        {

            $this->_controller = ucfirst($this->__controller);

            $this->_controller = $this->_controller . "_Controller";


            $this->_base_namespace = '\bizdir\bizvend\controllers\\' . $this->__controller . '\\' . strtolower($this->_controller);

              //use $this->_base_namespace as $this->_controller;

           $this->controller = new $this->_base_namespace;

            return $this->controller;


        }


}
请参阅我正在测试$this->\u控制器的样式或脚本的地方。发生的情况是在链接和脚本标记中,目录(或/styles/或/scripts/)被设置为命名空间中的控制器,路由器类正在尝试查找styles\u控制器类或scripts\u控制器类。当我达到这一点时,我可能还需要测试图像

希望这能帮别人省去几个小时的头痛


任何更干净的方法。。。我愿意接受建议。

这是一个丑陋的黑客行为,但它确实有效:

/**
 * Sets the appropriate controller
 * 
 * 
 * @return object $this->controller
 */ 

private function setController() 
{

   $this->_seo_uri = $this->seoUrl();

   $this->__controller = array_shift($this->_seo_uri);

        if ($this->__controller == 'styles')
        {
               /* dev purposes only. php will return error that gets 
                  appended to end of file.
                */
          ini_set('display_errors',0);

          /* include will return file with mime type 'text/html 
             thus not interpreting file as stylesheet
           */
           header('Content-type: text/css');  

           // readfile works too. your choice...   
           //readfile($_SERVER['DOCUMENT_ROOT']. '/styles/style.css');

             include ($_SERVER['DOCUMENT_ROOT']. '/styles/style.css'); 


        }
        elseif ($this->__controller == 'scripts')
        {
               /* dev purposes only. php will return error that gets 
                  appended to end of file.
               */
          ini_set('display_errors',0); 

             include ($_SERVER['DOCUMENT_ROOT']. '/scripts/gui.js');


        }
        else 
        {

            $this->_controller = ucfirst($this->__controller);

            $this->_controller = $this->_controller . "_Controller";


            $this->_base_namespace = '\bizdir\bizvend\controllers\\' . $this->__controller . '\\' . strtolower($this->_controller);

              //use $this->_base_namespace as $this->_controller;

           $this->controller = new $this->_base_namespace;

            return $this->controller;


        }


}
请参阅我正在测试$this->\u控制器的样式或脚本的地方。发生的情况是在链接和脚本标记中,目录(或/styles/或/scripts/)被设置为命名空间中的控制器,路由器类正在尝试查找styles\u控制器类或scripts\u控制器类。当我达到这一点时,我可能还需要测试图像

希望这能帮别人省去几个小时的头痛

任何更干净的方法。。。我愿意接受建议