4
First I apologize for not being able to express myself correctly, I am learning php yet and I came across the following problem. I’m setting up a site for studies and at the root I created the folders:
- css (where is the materialize file I need to call)
- template (where I created a file called
cabecalho.php
and in it I keep the call to the materialize css file and my navbar) - Tasks (where I created the file
tarefa.php
which by including call thecabecalho.php
in the template folder and have the problem).
In the root folder I have the index.php
In the index.php
I give the following include:
include ('template/cabecalho.php');
It then loads my header by calling the materialize css file and my navbar. In the.php header file I call the materialize css file as follows:
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
Even there everything perfect, my index loads normally.
My problem happens when I access the file tarefa.php
, when I give include no cabecalho.php
it does not load the materialize file getting totally disfigured my navbar and not loading the framework.
In the tarefa.php
my include got like this:
include ('../template/cabecalho.php');
With this it loads the navbar no more the file . css of materialize.
Follow prints:
This is because the files are at the same level, but in different directories, you just need to change 'css/materialize' to '.. /css/materialize'
– AnthraxisBR
Doing this right in the.php task file but in the index.php it is not configured since it calls the same.php header and it is not able to access the materialize file that is inside the css folder at the root. I’m looking for a solution that works for both
– João
Well, I couldn’t quite understand how you make the inclusions, but from what I’ve seen this order has no sense or need to be made, why include a file that will include another ? from the moment a include is given, what is in the included file becomes part of the file that requested the inclusion, so if you include it in the index, you would have to point as if the.php header was part of the index.
– AnthraxisBR
You can print out your file folders?
– Lucas de Carvalho
And kind of confusing and probably not the right way to do it, plus what I’m doing and the following, the index.php file is at the root and the tasks.php file is inside the tasks folder. Both give include in the header.php that is inside the template folder. Here comes the problem why the.php header file calls the materialize.css file that is inside the css folder. Just as the index.php file and tasks.php are in different directories I end up having error in the call of the file materialize.css inside the file cabecalho.php
– João
I added 2 prints to the question, I can’t add more because my reputation is low.
– João
Try it this way: href="/css/materialize.min.css"
– Diego Schmidt
In the index, Voce includes.php tasks, in.php tasks.Voce includes.php header, and in the header you include css/materialize, that’s it ?
– AnthraxisBR
Both in index.php (which is at the root) and in the task.php (which is in the task folder) I give a include in the.php header that is in the template folder. There in the header.php I only have html call the file materialize.css that is inside the css folder. Looking through the structure print to understand. The problem is that when I open the.php task in the browser it cannot locate the path of materialize.css
– João
Place a variable at the beginning of the pages (before include header) $page="index" in index.php and $page="task" in task.php. In the.php header make an if Else. If ($page=="task"){ .. /css/materialize }Else{ css/materialize
– user60252
I avoid this problem by putting everything out of folders, I just leave inside the images folders.
– empalamado