base_url() for everything? |
[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..?
[eluser]InsiteFX[/eluser]
root - - assets - css - img - js index.php Search forums for asset and wiki. InsiteFX
[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.
[eluser]InsiteFX[/eluser]
Code: <!-- set javascript base_url --> InsiteFX
[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. |
Welcome Guest, Not a member yet? Register Sign In |