I design and develop websites using php. I use
`includes(layouts/header.php);`
in every php page across my website. My directory structure is:
library
layouts ( header, footer, sidebar )
css
js
index.php
about.php
but now if I create new dir to keep, say, admin files or staff files or user files in different folders like:
library
layouts ( header, footer, sidebar )
css
user
index.php
login.php
myaccount.php
js
index.php
about.php
Now if I do
include('../layouts/header.php');
in my file under user dir then I don't get css in the page. That is because the relative path to .css file changes.
I want to know how to manage all this. Is there any way or I have to write new, say, user_header.php in layouts folder?
Use a global variable for site path and combine that with the path of your css file relative to your application root path.
for example in your header.php file define:
$SITE_PATH = "THE_PATH_TO_YOUR_WEB_APPLICATION/";
and then when you want to echo the link tag for css use:
<link rel="stylesheet" href="<? echo $SITE_PATH;?>css/yourCssFile.css" type="text/css">
Related
for my assignment next week we have to know following:
We get a template (not a Joomla template, but a website template with existing html and css + images). This template we have to "import" into Joomla and then add the menus, articles, etc. in Joomla for it
We have to just delete the protostar template files and paste in the template files, then rename the index.html to index.php
When I do this it works however with no css (because of the paths to css and images).
For example the standard path from my template is this:
<link rel="stylesheet" href="css/animate.css">
This, however, won't work.
I tried a few things and that worked:
<link rel="stylesheet" href="templates/protostar/css/animate.css">
But I don't know why templates/protostar is the root? I thought the root is the folder in which the index.php is located?
If I do the same with the images
<div class="fh5co-portfolio-figure animate-box" style="background-image: url(images/work_1.jpg);"></div>
to <div class="fh5co-portfolio-figure animate-box" style="background-image: url(templates/protostar/images/work_1.jpg);"></div>
this won't work. So the pictures still won't show on the page.
So could anyone explain to me that behavior and how to do this right?
I’m creating a new site and in order to have the same navigation and footer in each page I created a footer and navigation files .
I put footer.php and navigation.php inside folder /include
this it the structure of my site so far:
old site folder
index.html
other.html
New Site folder
/index.php
/biography.php
/style folder (style.css, responsive.css)
/images folder
/include folder (footer.php , navigation.php)
/media folder (videos.php)
the problems I have are with images included in footer and links within the navigation menu
for instance, on file biography.php I put on the footer area this calls the footer just fine but the images I have in the footer are broken (the images reside in the images folder)
the same for navigation on biography.php, I have but the links in nav menu go back to old site folder, for instance index.php links to oldsite/index.php instead of newsite/index.php
the file videos.php footer and navigation display all ok , images and links
I guess the issue is with the paths, I tried adding / and dots but it doesn’t work
I don’t know what to do.. :(
You can define definite path to your images:
for example:
<img src='<?="$_SERVER['HTTP_HOST']"."/images/footer.png"?>' />
you can include from your /include/footer.php with
dirname(__FILE__).'/images/filetoinclude'
Edit:
If you want to display images that are served by your webserver, you will have to specify either absolute path /images/images.jpg or the fully qualified path including its host as suggested above
Your problem can solve by HTML.
You must use absolute path in image source.
<img src="/images/footer.png" />
When you use slash in first of src, that mean start path from root of site.
index page is styled while rest of the pages are not.When i checked cascading style sheets(CSS) files in browser, I was surprised to see those CSS files are not accessible for all pages except of Index.ctp. All pages are in same folder and same links are given to access cascading style sheets then why those CSS files are not accessible for other pages.I tried enough to resolve this but could not. i tried to fin solution of this on Google but can't find any solution.
Include the stylesheets on default.ctp layout in View/layout not on index.ctp.
in your comment
controler name is FrontsController and folder iname is Fronts. css and js files are in css, js folders respectively. i using this way to add css file in about page. – user3623305 35 mins ago
add a comment
change path for css to be href="/css/reset.css"
Anyways it better to include your css files using html helper like this
echo $this->Html->css('css_name');
if your css file is at app/webroot/css, and it's name is main.css, use
echo $this->Html->css('main');
For more information look here http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::css
Hello I'm having my first serious go with PHP to create a sample script for my self. It has a basic structure, in my root folder I have:
index.php
core folder (holds most of my php function files)
includes (holders my header.php and footer.php)
sites - (sites has 3 further folders site A, B, C)
CSS
js
All pages are made up by taking a header.php and footer.php from the includes folder and then each page has its own content in the middle. The header.php contains (as well as basic html and links to javascripts stylesheets ect) includes from core folder like so:
include_once '/core/connect.php';
Now these all work great using the index.php which provides links to the 3 different sections of the site, sitea, siteb and sitec.
But when you navigate out of the document root to say /sites/sitea/index.php all those links are now broken.
What is the best way to go about building the links in the header.php section so they are relative site wide no matter which folder you are in?
The idea behind this is that you do only have ONE file for each process.
So process all pages through index.php
index.php would contain, for example,
require('header.php');
include('content.php');
require('footer.php');
That way, it won't break the site if your content doesn't show.
Your index is always loaded from the same path, so header/footer wouldn't change. Just content.
When you're including you want to use a real path, not a relative path...
require_once ($_SERVER['DOCUMENT_ROOT'].'/includes/header.php');
/* something happens here */
require_once ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.php');
The best way is to always use physical path from wherever you are - this way every page that include other page with includes won't get break:
PHP 5.2 and down:
require(dirname(__FILE__) . '/core/connect.php');
PHP 5.3 and above
require(__DIR__ . '/core/connect.php');
I am using agile toolkit for one of my projects. When I create a sub folder under page folder, CSS and JS are not picked from atk4 folder and I have to copy those css and js under templates folder. Is this the right way of doing this?
Yes. With Agile Toolkit, the files are loaded from atk4/* by default. If you want to override any of those files including templates, css, images, classes or templates, you should copy them outside.
for example:
atk4/template/jui/css/general.css -> template/jui/css/general.css
atk4/lib/Tabs.php -> lib/Tabs.php
If you are including CSS files or linking to images, it's a good practices to use
<?template?>img/myimage.png<?/?>
in your own templates. That instruct Agile Toolkit to locate the resource and links to it properly.
As romans said, you can put your own files in the /templates/default/css folder (It's called jui in 4.0 but default in 4.1) and these should be picked up by the pathfinder.
You can also add additional directories to the list searched by adding them in Frontend.php like this.
$this->addLocation('atk4-addons',array(
'php'=>array(
'mvc',
'misc/lib',
'sterling/jqplot/lib',
),
'css'=>array(
'sterling/jqplot/templates/js/jqplot',
),
so now the pathfinder will also search for css scripts in the directory specified and i can add the following line into my page code.
$p->api->template->append('css_include', '<link type="text/css" href="'.$this->api->locateURL('css','mysite.css').'" rel="stylesheet" />'."\n");
Relative path,
Look:
Some Directory
templates/index.html { `<script src='test.js'></script>` }
index.php
If you want include index.html with test.js you must change relative path - from test.js to templates/test.js
edit: look : Click