Fatal error -> base_url() - what am I doing wrong? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Fatal error -> base_url() - what am I doing wrong? (/showthread.php?tid=9060) Pages:
1
2
|
Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]ICEcoffee[/eluser] I get this error when loading a simple view file from my default controller: Quote:Fatal error: Call to undefined function base_url() in H:\xampp\htdocs\ci2\application\views\home_view.php on line 6 Line from 'home_view.php' Code: <link rel='stylesheet' href='<?php echo site_url(’styles/style.css’) ?>' type='text/css' media='screen' charset='utf-8' /> my config file: Code: |-------------------------------------------------------------------------- Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]ontguy[/eluser] I think you just need to load the url helper before loading the view: Code: $this->load->helper('url'); Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]ICEcoffee[/eluser] I followed the suggestion to load the helper, I put it in the index function. I changed the php in the view to include double quotes as per codeigniter user manual: Code: <link rel='stylesheet' href='<?php echo base_url("styles/style.css"); ?>' type='text/css' media='screen' charset='utf-8' /> and now I just get a plain page, no applied style, no errors, just text. The browser output is: Code: <link rel='stylesheet' href='http://localhost/ci2/' type='text/css' media='screen' charset='utf-8' /> Notice it does not include the path sent to the method/function, according to the browser output. What else am I doing wrong? Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]ICEcoffee[/eluser] I changed the code, instead of passing the rest of the path to base_url, I appended it: Code: <link rel='stylesheet' href='<?php echo base_url() . "styles/style.css"; ?>' type='text/css' media='screen' charset='utf-8' /> this resulted in the full path to the style folder/file, in the browser output: Quote:<link rel='stylesheet' href='http://localhost/ci2/styles/style.css' type='text/css' media='screen' charset='utf-8' />[/code] but I'm still getting text only ouput and no style formatting. I checked the path was correct, I even felt paranoid enough to check the stylesheet itself just to make sure it still had code in it, and it does. I think I'm at a loss. Can anyone shed any further light? Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]Lone[/eluser] So just to verify - if you put the following in your browser as a URL the css file shows? Code: http://localhost/ci2/styles/style.css Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]ICEcoffee[/eluser] I tried that and got a 404. knowing that the path is correct, I checked and removed my .htaccess file, the style page now displays. I only included it to take out 'index' in the URL. My htaccess file was based on the example given in the codeigniter user guide. can you tell me what is wrong with my htaccess file: Code: RewriteEngine on or does it not matter if I intend to rewrite the urls anyway using the url helper? Sorry if these are basic questions. Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]ontguy[/eluser] I've been using this one from the CI wiki: Code: <IfModule mod_rewrite.c> Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]ICEcoffee[/eluser] @ontguy - Thanks for your help, I'll give that a bash. At least we overcame the initial issue of stylesheet not being parsed. Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]Pascal Kriete[/eluser] Really simple solution. Add styles to your RewriteCond: Code: RewriteCond $1 !^(index\.php|styles|images|robots\.txt) Fatal error -> base_url() - what am I doing wrong? - El Forum - 06-10-2008 [eluser]evanwalsh[/eluser] Just so you know, base_url() doesn't take any arguments. However, site_url() does. |