base_url() for everything?

#1
[eluser]universal_serial_bus[/eluser]
Hi there,

I'm developing with CI and I've the next problem:

I'm migrating some views from an old project to CI, and this views have relative routes to css, js and img.
So, if I keep this routes (relative to index file in CI root directory) it only works on index entry of every controller...

I mean, if I do something like www.example.com/example, the index function of the example controller loads the view and it works fine, but if I do www.example.com/example/view/1, the same view is loaded, but now relative routes are not found (css, js, img,...).

I've fixed it using base_url() with every link, but, it's necessary to do this with every route?

I hope I've been clear...

Thanks in advance !

EDIT: Anyway, with the way I've solved it I still have problems with the images linked in the js files... any solution..?

#2
[eluser]InsiteFX[/eluser]
root -
- assets
- css
- img
- js
index.php

Search forums for asset and wiki.

InsiteFX

#3
[eluser]universal_serial_bus[/eluser]
Thanks, that's a good solution, but finally I've used base_url() everywere...

For js files, I've a js named settings.js with just this parameter:

var settings = { 'base_url' : 'www.example.com'};

And I use this javascript "base_url" to do the same that CI base_url() function.

#4
[eluser]InsiteFX[/eluser]
Code:
<!-- set javascript base_url -->
[removed]
    <![CDATA[
    base_url = '<?php echo base_url();?>';
    ]]>
[removed]

InsiteFX

#5
[eluser]Vheissu[/eluser]
I tend use a base href in the head of my views like so (just under the title tag)

Code:
<base href="<?php echo base_url(); ?>" />

The plus about this is that it will append your base url to the front of everything without a http or www on it. So if you have a link with just example set as it's href, the base href will turn it into baseurl/example instead.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.