Recently I decided to give some more time to my blog and write some short but interesting posts. I will be writing some posts about custom helper functions that I have written which helps me in application development.
First on the list is a absolute path helper which creates an absolute path, relative to the base of the application. I call this function base_path(‘relative/url’);
-
function base_path($relative_path_location){
-
return base_url().$relative_path_location;
-
}
-
}
The above is the code which will go into your helper file. The function formulates an absolute url from the given relative path based on base path of the application directory. It uses the existing base_url() helper function in codeigniter. So, you have make sure the URL helper is already loaded.
Example:
Suppose you want to tag an image which is located at “application-root/images/picture.jpg” to give its absolute URL in the img tag you can type as follows in your template/view file.
-
<img src="<?php echo base_path(‘images/picture.jpg’);?>" alt="picture"/>
If you application is hosted at domain.com then it will give http://www.domain.com/images/picture.jpg as the returned path where http://www.domain.com/ is the base_url();
thanks,
thephpx