Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter access base_url() inside error_404.php

When 404 Page Not Found error occurs application/errors/error_404.php template is used in CodeIgniter. I need to access the base_url() function inside that template. Any suggestion on how base_url() or site_url() functions can be accessed inside error_404.php will be really helpful.

like image 374
S.K Avatar asked Mar 10 '16 09:03

S.K


2 Answers

you might want to use this simple trick. Just change the code below:

<?php echo base_url() ?>

to:

<?php echo config_item(‘base_url’); ?>

credit for https://www.petanikode.com/codeigniter-base-url-404/ this work for my case

like image 90
ana Avatar answered Oct 13 '22 09:10

ana


Try following in application/errors/error_404.php

$CI =& get_instance();
if( ! isset($CI))
{
    $CI = new CI_Controller();
}
$CI->load->helper('url');
echo $CI->base_url();
like image 26
N.J Avatar answered Oct 13 '22 08:10

N.J