- This topic is empty.
-
AuthorPosts
-
June 22, 2011 at 7:21 pm #33244sebgonzMember
Let me start off with a little bit of history… I’ve been asked to clean up the intranet pages at my place of employment. Currently, they’re some hacked together PHP that doesn’t have a template or anything, basically no style to the site and uses some god-awful table styles (no table styles?) to display the information.
The basic structure of the site is fine, meaning the way it’s pulling information from the databases. What I want to do is clean it up, make it attractive to use, and create a template style structure to it a la WordPress. (header.php, sidebar.php, footer.php) Where I’m running into issues is with my includes and having my scripts and css linked properly. For example…This works fine when used on the root (in header.php), but when I try to use the same file in a different page, usually on a different level, I don’t get any stylesheet loading because the file is obviously not in the same level as the page I’m currently on.
What I want to be able to do is something WordPress-esque like
When I do this though, it doesn’t work. How can I get this to always find the root directory of the site (intranet) without breaking? I’d prefer to do it this way because, from what I’ve read, it’s more configurable over using direct paths.
Any help would be appreciated. Oh… did I mention I’m developing this in XAMPP?
June 22, 2011 at 8:30 pm #82161DboGMemberThe simplest solution would be to precede the CSS path with a /, which will always make the starting point the site root, regardless of where it’s being called.
June 23, 2011 at 2:44 am #82176ddliuMemberBasicly, you can define a BASEURL and use it as a prefix with your assets.
For example, you have a website with this url: http://example.com/blog, you can define it:
define('BASEURL','/blog');
or if your website is http://example.com, you can define it:
define('BASEURL','');
then in your template file ,use it like this:
I’m using the similar way in some of my projects, and it worked perfect for me.
June 23, 2011 at 12:43 pm #82205June 24, 2011 at 12:31 pm #82291sebgonzMemberWhere do I need to define BASEURL? Would that be in my index.php or header.php file?
June 24, 2011 at 12:49 pm #82301noahgelmanParticipantSeriously, it’s best to just link to the root like DboG suggested. defining the base url in php is just adding another step and is pretty pointless
June 24, 2011 at 7:10 pm #82356ddliuMember@sebgonz, you can define it any where before the template.
@noahgelman, yes I agree that @DboG’s way is simple and strait-forward, but it’s not that flexible and not configurable. What if the app is not at the root URL? For example, it’s a news app located at http://www.example.cm/news, or a blog app located at http://www.example.com/blog, or even more, you have to change it to another location someday…Anyway, if your app is located at the root and will not be changed, @DboG’s way is recommended.
Hope it’s clear.
June 24, 2011 at 7:14 pm #82357noahgelmanParticipant@ddliu, why does it matter where it’s located? Linking to the root makes it irrelevant. The stylesheet would apply the same way to the index page as well as a page a hundred folders deep.
June 25, 2011 at 7:39 am #82371ddliuMember@noahgelman, yes I agree with you that it should be linking to the root.
The only different point I mean is the flexibility.
If your app don’t go into following situation, just forget it.
You have an app hosted at http://www.example.com/myapp,
your folder structure like this:
myapp/
index.php
assets/
css/
main.css
js/
main.js
So in your template you might define the assets like this:
Someday you decided to change it to http://www.example.com/myapp-with-new-name,
ok you have to find each template and change the links.Someday you decided to change it to http://www.example.com/apps/myapp…
It’s best to make an application flexible and can be put in any location if possible I think. It’s the same thing like:
1. You need to have a site url configured in WordPress.
2. You need to define the attachment path in many of your applications.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.