base_url() on error pages not working? |
I want to have nice good looking error pages. For this I need to get some CSS and JS files. But for some odd reason using base_url() does not work on the error_pages. I could of course just use href="/css/style.css" and tell it to get it from the root folder. But the website could very well be put in a different folder than the root folder. So using the / is not an option.
So my question now is why doesn't base_url() work on an error page? I have autoloaded it so shouldn't it be working? This is what I tried when I was trying to get the base_url() from the error_404 page in the view. In my autoload.php I have included the helper url Code: $autoload['helper'] = array('url', 'form'); And in my error_404 page (application/views/errors/html/error_404.php) I am echoing the base_url like so: Code: <?php echo base_url(); ?> This is the error I'm getting: Code: An uncaught Exception was encountered I'd rather not make any changes in the system folder since I don't want to redo the process every time I update Codeigniter folder. System: Codeigniter 3.0.6 PHP 7.0.8 Nginx 1.11.1 UPDATE: I'd like to call base_url on every error page (db, 404, general, php, etc.). http://stackoverflow.com/questions/38048...utoloading
You already know why, and that same StackOverflow thread already gives a solution.
Code: <head> What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-17-2016, 08:13 AM)Narf Wrote: You already know why, and that same StackOverflow thread already gives a solution. I know why, and thank you for explaining it on the bugtracker however the thread does not give me a solution. It only gives the solution for 404 errors and not for database, exception, general and php errors. (08-17-2016, 05:57 PM)InsiteFX Wrote: I could use this and it will reduce the amount of href's I have to change, but I wish to make something that gets our base_url from the config. I just want to type in the config.php our base_url and then in the custom error pages somehow use this base_url. (08-17-2016, 11:51 PM)AzaZPPL Wrote:(08-17-2016, 08:13 AM)Narf Wrote: You already know why, and that same StackOverflow thread already gives a solution. Perhaps questionable for "general" errors, but you're not supposed to show any of the others to your users, so I don't see the problem with that. (08-18-2016, 02:11 AM)Narf Wrote:(08-17-2016, 11:51 PM)AzaZPPL Wrote:(08-17-2016, 08:13 AM)Narf Wrote: You already know why, and that same StackOverflow thread already gives a solution. First of all congratulations on your 1000th post. Yes you can say that. But even if I don't wish to show the user the custom error pages I might want to send error reports to a different server on the same domain. For that I'd need my base_url agreed? I just want to be able to get the base_url from the config file on a custom error page. (08-18-2016, 03:21 AM)AzaZPPL Wrote:(08-18-2016, 02:11 AM)Narf Wrote:(08-17-2016, 11:51 PM)AzaZPPL Wrote:(08-17-2016, 08:13 AM)Narf Wrote: You already know why, and that same StackOverflow thread already gives a solution. Try this: Code: $base_url = load_class('Config')->config['base_url'];
And if that does not work you can always define your own base_url
PHP Code: <?php define('BASE_URL', 'your base_url'); ?> What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-18-2016, 06:55 AM)Narf Wrote:(08-18-2016, 03:21 AM)AzaZPPL Wrote:(08-18-2016, 02:11 AM)Narf Wrote:(08-17-2016, 11:51 PM)AzaZPPL Wrote:(08-17-2016, 08:13 AM)Narf Wrote: You already know why, and that same StackOverflow thread already gives a solution. Works like a charm! Thanks Narf! |
Welcome Guest, Not a member yet? Register Sign In |