base_url() for everything? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: base_url() for everything? (/showthread.php?tid=33723) |
base_url() for everything? - El Forum - 09-06-2010 [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..? base_url() for everything? - El Forum - 09-06-2010 [eluser]InsiteFX[/eluser] root - - assets - css - img - js index.php Search forums for asset and wiki. InsiteFX base_url() for everything? - El Forum - 09-06-2010 [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. base_url() for everything? - El Forum - 09-06-2010 [eluser]InsiteFX[/eluser] Code: <!-- set javascript base_url --> InsiteFX base_url() for everything? - El Forum - 09-06-2010 [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. |