I'm using materializecss as a framework but I have many problems.
I have an issue with links and my CSS. I make several include's files to make it easy for me. But when I test my links on the browser in the console's chrome: my CSS is not found and refer to a directory that it doesn't exist!
<link type="text/css" href="../css/admin.css" rel="stylesheet" />
This CSS is in the file header.inc.php which is in the file admin/
<?php
include( './inc/header.inc.php' );
?>
<title>Ma page d'administration</title>
</head>
<body>
<div class="row">
<?php
include( './inc/nav.inc.php' );
?>
</div>
My links at ./inc/nav.inc.php are not working at all!
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo hide-on-small-only"><i class="material-icons">lock</i>Section d'administration</a>
<ul class="right">
<li><a href="../index.php"><i class="material-icons">home</i></a></li>
<li><a href="../portfolio.php"><i class="material-icons">add_a_photo</i></a></li>
<li><a href="../rubriques.php"><i class="material-icons">playlist_add</i></a></li>
</ul>
</div>
</nav>
The browser doesn't find these files portfolio.php and rubriques.php
Browser make the link like it was at root directory.
http://localhost/portfolio.php : wrong link
http://localhost/admin/portfolio.php : right link
here the error message:
admin.css Failed to load resource: the server responded with a status of 404 (Not Found)
Roboto-Regular.woff2 Failed to load resource: the server responded with a status of 404 (Not Found)
Roboto-Regular.woff Failed to load resource: the server responded with a status of 404 (Not Found)
admin.css Failed to load resource: the server responded with a status of 404 (Not Found)
May be you can help me because it really makes me crazy. I really don't understand why links are going to root directory.
Thanks for your help! I appreciate.
A problem you often see when including php files is linking. The moment one php file gets included in another, it will use the directory from the page you included it into (in your case header.inc.php
)
So if you had a directory like this:
index.php
/inc
--header.inc.php
--nav.inc.php
/admin
--portfolio.php
You will have to change any include in nav.inc.php
to <a href="admin/portfolio.php">
. The same would go for other files.