confusion with urls |
[eluser]leet_2k[/eluser]
Hi guys, I have just started up on codeigniter and am bit confused about urls. I have been using relative urls in all my links till now.For eg: <link href="css/common/css-reset.css" rel="stylesheet" type="text/css" media="all" /> I have doing the same with CI too N it seemed to work until now. My problem is as follows: I have created a header.php and footer.php and put them in includes folder under views That is: Views-> includes -> header.php & footer.php (-> indicates that they are inside a folder) In my header.php, I have the followed code(Notice How I used relative URLs): Code: <?php echo $title; ?></title> In a nutshell, I load this header.php and footer.php from template.php (code is below) Code: <?php $this->load->view('includes/header'); ?> From my controllers, I pass in the $css_specific and $title variables. So for example, if I want to create a contact us page, Code: class Contact extends Controller{ Now when the validation fails and I load the index controller (by using - $this->index(); ), the URLs seem to be screwed up. The css and the js files in the header files do not have proper URLs. I have also tried redirecting the page to '/contact' but then the form resets to default text which I don't want SOLUTION POSSIBLE: 1) I have changed my css url(the css of contact page - that is $css_specific NOT header.php) to ABSOLUTE and it works. So,I guess if I change all the urls to ABSOLUTE,it'll work. Is there ANY other way?
[eluser]cahva[/eluser]
Use URL helper. You'll be using it a lot so put it to autoload. Change your view code's urls to this: Code: <link href="<?php echo base_url() ?>css/common/css-reset.css" rel="stylesheet" type="text/css" media="all" />
[eluser]leet_2k[/eluser]
Hi cahva. Thanks for replying. As to your suggestion, isn't there a easier way. I mean, I'll have to change lots of urls...
|
Welcome Guest, Not a member yet? Register Sign In |