Let me explain my need with simple example.
I have folder called "Website" Inside that some sub folders and files.
Website(Main-Folder)
pages(sub-folder)
(files)
page1.php
page2.php
target_page(sub-folder)
(file)
target.php
menu(sub-folder)
(file)
menu.php
index.php (this file is in main folder)
This is my sample folder view, I just included menu.php(navigation menu with links)file in my both pages and index.php file.
In menu.php i have a nav link to target.php page
So, to
access target.php file in
index page mean i have to use Target
Target
access target.php file inside
the pages folder mean i have to use
Target
Is there any short way to access that target page, because I don't like to create multiple menu.php file and set the different location for same file.
Sorry for bad English, Thanks.
[UPDATED]
The best alternative is to define your root path once and for all !
We use another file that we could call whenever we need the PATH. Like for example in settings.php that we save near index.php:
define('My_ROOT' , 'http://'.$_SERVER['HTTP_HOST'].'/');
Then whenever needed, we require that file and so we could write links like follwing :
Target
P.S: Please notice that in my first Answer I used the file path and that could be used for relative inclusion not Frontend links !
Just put your href starting with "/" :
link
I am trying to use PHP to read, then modify and echo an HTML file.
The included HTML file contains external JS, CSS references - all relative paths
for example...
<script src="js/myJavascript.js"></script>
Problem :
The location of the PHP modifier file is not the same as the location of the included HTML file, and therefore the external includes are not loaded. I guess...
The solution of using absolute paths to reference external resources in the HTML file is not ideal to say the least...
What can be done to tell PHP that the path context of the included HTML file is the same as the directory from which it is being included and NOT the directory of the modifier file?
Thanks!
Found a solution!
<base href="path_to_the_html" target="_blank">
according to W3Schools :
This would specify a default URL and a default target for all links on a page...
I know a little bit about relative path. Suppose, I have a project on codeigniter. There are 4 controller such as with function name:
1. Admin->index,profile,add_student,edit_marks,make_admin,
2. Teacher->index,add_marks,update_marks
3. Student->index,view_teacher,view_result
4. Guest->index,view_Student, view_marks,view_result
From these, How can I use them as relative path ?Remind it,some times I go one controller to another controller, such as profile,view_marks is a common function for all, so every one access it.
For images or file can I use relative path ? Then,Suppose I have a image at root folder as
->root_folder/template/images/a.png. How can I use it as relative path ?
Really, I need the core knowledge of relative path with application in codeigniter.
You should use codeigniter constants defined in root/index.php
To get Root path use
FCPATH
It returns
Path upto root folder where your codeigniter is installed.
So in your case , it will be
FCPATH . 'template/images/a.png';
I assume you're looking for path not URL.
At last I have found the answer that is:
It is not necessary to use base_url or site_url every times for link.
All time use:
/controller_name/function_name
Such as for a anchor link on viewing admins's profile code as(I hope, this technique is called relative path). It decrease time to route it.
Admin Profile
What's wrong with using this for the image path?
base_url('path/to/image')
If having senario like
ROOT
|____APPLICATION
|____ASSETS
| |________ CSS
| |________ JS
| |________ IMG
|____SYSTEM
then you can access the css as follows:-
<script type="text/javascript" src="<?php echo base_url();?>assets/css/style.css"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/getinfo.css"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/img/image.png"></script>
The current accepted answer works fine, but it is not relative. For instance: if the website would be replaced from the root to a subdirectory, the url wouldn't work anymore.
More on this same topic I found here: How can I display images with the Codeigniter php framework?
The answer in that topic recommends not working with relative paths, but personally I would like to see this possible within modules (the MX-plugin for CodeIgniter).
So here's a possible way of working with relative paths I found:
<?php $path = base_url(str_replace(FCPATH,"", __DIR__ )).'/'; ?>
Example usage:
<img src="<?php echo $path;?>../assets/img/myImage.png" />
for instance: if the this html would be used in /modules/mymodule/views/someviewfile.php the output will be yourdomain.com/modules/mymodule/assets/img/myImage.png
i created a controller and actions in zend.
if i type
"http://localhost/cms/public/controller"
then the css file is loaded correctly
but if i type
"http://localhost/cms/public/controller/action"
then headlink appears like
href='http://localhost/cms/public/controller/css/style.css" and it does not work.
Please help me!!
this is the correct way to add css & javascript to ZF Application
<?php
$this->headLink()->appendStylesheet($this->baseUrl("css/reset.css"))
->appendStylesheet($this->baseUrl("css/text.css"))
->appendStylesheet($this->baseUrl("css/960.css"))
->appendStylesheet($this->baseUrl("css/demo.css"));
echo $this->headLink();
$this->headScript()->appendFile($this->baseUrl("js/jquery-1.4.2.min"))
->appendFile($this->baseUrl("js/jquery-ui-1.8.2.custom.min"));
echo $this->headScript();?>
You have your css path set to "css/style.css". Set the css path relative to the root path. If your css is in /html/style/css/style.css, the link would be "/style/css/style.css"
Always remember the leading slash and make the static paths relative to the root dir(of the website).
I have a page with some HTML in it.
and I need to set the src property to the location of pictures.
How can I achieve that with Kohana PHP ?
Thanks.
It depends on where the images are located. In a standard Kohana install, the files are located in your document root and are accessible with the url::file() call, eg:
<?php echo url::file("images/foo.gif") ?>
would refer to:
http://example.com/images/foo.gif
Reference: http://docs.kohanaphp.com/helpers/url#file