0

I am trying to make a simple application in PHP (MVC). I made the routing and in Views i created an inc folder where head.php - header.php - footer.php exists. The head.php is included in header.php. In the head.php title there is a $pageTitle variable. The thing is that when i include the header.php in other files even if the $pageTitle is changing (according to the new value) no styles from css file is presented!!!

my head.php file is

<head>
<meta charset="utf-8">
<title><?php echo $pageTitle ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../src/css/bootstrap.min.css" rel="stylesheet">
<link href="../src/css/main.css" rel="stylesheet">
<script src="../src/js/bootstrap.min.js"></script>
</head>

my header.php is

<!doctype html>
<html>

<?php 
define( 'ROOT_DIR', dirname(__FILE__) );

include( ROOT_DIR.'/inc/head.php' );
// include 'inc/head.php';
// include '../app/views/inc/head.php'; 
?>

and i include the header

<?php 
$pageTitle = "login-register | Twitter";

define( 'ROOT_DIR', dirname(__FILE__) );
include( ROOT_DIR.'/inc/header.php' );

// include '../app/views/inc/header.php'; 


?>

I tried many different options but nothing worked. I searched and tried everything (i think)

5
  • What is the browser output for the CSS path? Commented May 8, 2015 at 10:09
  • Well i do not why but there is two src folders instead of one!!!! src/src/css/main.css . But it should be src/css/main.css Commented May 8, 2015 at 10:16
  • @Stergiosm what is the path to the /src/css from the root of the application? Commented May 8, 2015 at 10:17
  • Thank you. I fixed it. Really easy. The browser output showed me that i shouldn't write the src folder at the link in the head.php file. Commented May 8, 2015 at 10:18
  • Don't be lazy using relative urls. Always use Absolute urls. eg. /src/css/main.css Commented May 8, 2015 at 10:20

3 Answers 3

1

Instead of using a relative path to your /src/css and /src/js, try using an absolute path like this -

<link href="/src/css/bootstrap.min.css" rel="stylesheet">
<link href="/src/css/main.css" rel="stylesheet">
<script src="/src/js/bootstrap.min.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

0

You are using relative paths to include the CSS. Relative paths will be relative to the current url in the address bar (which might have a subdirectory in it).

To check the result of a relative path copy the relative path from the href to the clipboard (ctrl+c) and append it to the address that is already in the browser address bar.

Example 1: Href value: ../src/css/main.css Address bar initial value: http://example.com/directory/file.ext Modified address bar value: http://example.com/directory/../src/css/main.css

The result of the above example will be computed as http://example.com/src/css/main.css which should normally be correct.

Example 2: Href value: ../src/css/main.css Address bar initial value: http://example.com/directory/file.ext Modified address bar value: http://example.com/directory/../src/css/main.css

The result of the above example will be computed as http://example.com/subdirectory/src/css/main.css which isn't what you wanted.

Comments

0

How the folder structure looks like? maybe you do not need to put src for the path, or maybe you do not need to go up one folder from the path.

1 Comment

My login form is in the Twitter/app/views/login.php The header.php is in the Twitter/app/views/inc/header.php the head.php is in the Twitter/app/views/inc/head.php and finally the css file is in the Twitter/src/css/main.css

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.