0

I am learning MVC in PHP. The css and js files are not working in php pages.

I am using eclipse, xampp server.

This is my .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

<?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?

3
  • same project is running in Ubuntu where Apache and php is there Commented Mar 24, 2015 at 6:45
  • PHP code has nothing to do with CSS/JS. Check if your paths to CSS/JS files are correct in generated HTML file. Show us file tree and generated HTML (part where you link CSS/JS - usually header) Commented Mar 24, 2015 at 7:27
  • “How do I resolve this issue?” – by learning to understand how the resolution of relative URLs to absolute ones based on the current page’s address works … Commented Mar 24, 2015 at 12:43

3 Answers 3

1
RewriteEngine On

RewriteBase /clients

RewriteRule ^(css|images|scripts|js|png|jpg) - [QSA,L]
Sign up to request clarification or add additional context in comments.

Comments

0

if you have a bad rewrite for css,img..., then you add this line into your htaccess file up to your rule

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

Comments

0

Where you have included your CSS/JS files?

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..)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.