EllisLab text mark
Advanced Search
Relative paths
Posted: 04 January 2012 02:45 PM
Joined: 2011-05-17
156 posts

I have jquery lightbox working within codeigniter. All the files are in a public folder outside the application folder and it works fine. The only problem is that I have to modify the lightbox js file to give the absolute path to the plugin navigation images. And then I have to do it all again when I upload the file to a server.

What I would like to do is to use the convenient approach of the codeigniter url helper so that the image paths are relative to the site root and work the same locally as online.

Since the location of the files is public/images/image.jpg, I would have thought that a conventional approach to relative paths would have worked but, having tried mightily, it doesn’t and that might be something to do with the plugin, I don’t know.

But is there an equivalent of site_url() that will work?

Posted: 04 January 2012 07:40 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-05-19
286 posts

codeigniter is written in PHP, your question is related to path detection in javascript so you will get better answers in a javascript forum.

Try devshed.


CodeIgniter E-Commerce Shopping Cart Software

Posted: 05 January 2012 04:50 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-05-17
156 posts

OK thanks

Posted: 05 January 2012 05:20 AM   [ # 3 ]   [ Rating: 0 ]
Joined: 2006-03-25
1027 posts

What I do to get my js path correctly in all my js scripts is
putting this in my header:

<scr+ipt type="text/javascript">
base_url '<?php echo base_url();?>';

then you can just use ‘base_url’ as a variable in all your
javascript files.

Posted: 05 January 2012 10:00 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2011-05-17
156 posts

Like all good ideas, blindingly simple. Thank you so much LuckyFella73 - that is exactly what I will do!