简体   繁体   English

CSS和JS文件无法在PHP中工作

[英]css & js file not working in php

I am learning MVC in PHP. 我正在用PHP学习MVC。 The css and js files are not working in php pages. css和js文件在php页面中不起作用。

I am using eclipse, xampp server. 我正在使用eclipse,xampp服务器。

This is my .htaccess 这是我的.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME)} !-d
RewriteCond %{REQUEST_FILENAME)} !-f
RewriteCond %{REQUEST_FILENAME)} !-l

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

this is my bootstap.php 这是我的bootstap.php

<?php
class Bootstap {
   function __construct() {
    $url = isset($_GET ['url'])?$_GET ['url']:null;
    $url = rtrim($url,'/');
    $url = explode ( '/', $url );
    // print_r ( $url );

    if (empty($url[0])){
        require 'controllers/Index.php';
        $controller = new Index();
        return false;
    }
    $file = 'controllers/' . $url [0] . '.php';
    //print_r ( $file );
    if (! file_exists ( $file )) {
        require 'controllers/Error.php';
        $controller = new Error ();
        return false;
    }
    require "$file";
    $controller = new $url [0] ();

    if (isset ( $url [1] )) {
        if (isset ( $url [2] ))
            $controller->$url [1] ( $url [2] );
        else
            $controller->$url [1] ();
    }
  }
 }

How do I resolve this issue? 我该如何解决这个问题?

RewriteEngine On

RewriteBase /clients

RewriteRule ^(css|images|scripts|js|png|jpg) - [QSA,L]

如果您对css,img ...的重写不正确,则根据您的规则将此行添加到htaccess文件中

RewriteRule ^(css|images|scripts|js|png|jpg) - [L]

Where you have included your CSS/JS files? 您包括CSS / JS文件的位置?

As far as my knowledge, its not anything relates with .htaccess and MVC , in MVC , your basic css/js files are included in normal way like hows we are including with core PHP (with html start head tag etc..) 据我所知,它与.htaccessMVC没有任何关系,在MVC ,您的基本css/js files以正常方式包含,例如我们如何包含在core PHP (带有html start head标签等)。

I would recommend here to run your page in browser, and check view source. 我建议在这里在浏览器中运行您的页面,并检查视图源。 you must find out css/js pahts in source and issue can be here for wrong path (location not exactly set for public file includes), you can just correct and set right full path there to solve it 您必须在源代码中找到css / js pahts,问题可以在此处查找错误的路径(包括未针对公共文件精确设置的位置),您只需更正并设置正确的完整路径即可解决该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM