Welcome Guest, Not a member yet? Register   Sign In
Include Header File That Contains base_url()
#1

[eluser]TexMax007[/eluser]
Hello All,

Problem:

Editing error_404.php to match the layout of my site, I'm trying to include two files before the main content of the page. These files are called header.php and main_menu.php.

Code:
<?php

$path = APPPATH . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;

include_once(realpath($path . 'header.php'));
include_once(realpath($path . 'main_menu.php'));

?>
... More HTML here

It's finding the file correctly, but stopping the render when it reaches the first occurance of base_url() in my header.php

The error_log on my server says
Quote:Call to undefined function base_url() in ... header.php on line 19

It's not acceptable to remove the base_url()'s in either of these files.

Is there any way to fix this?

Thanks,

Max
#2

[eluser]vbsaltydog[/eluser]
You are using CI for your framework so why are you using includes?

Code:
$this->load->view('header');
....
....
#3

[eluser]TexMax007[/eluser]
Yea, that's what I thought. However, you can't really do that.

The error_404.php exists in the errors folder rather than the views folder, so simply doing this:

Code:
$this->load->view('includes/header.php')

doesn't work.

Then I thought about doing this:

Code:
$CI =& get_instance();

$CI->load->view('includes/header.php');

That didn't work either because the CI Super-Object isn't instantiated yet before the 404 error is thrown.

Refer to this post: http://ellislab.com/forums/viewthread/87398/#440462

At the end they suggest just including the files. Might work for some, but for me I ran into the aforementioned issue.

Thanks for the suggestion though.

Keep them coming!

#4

[eluser]CroNiX[/eluser]
@salty & TexMax, much of CI isn't available (it's not loaded yet) within the error_404 template. So you can't load() or use things like base_url(), unfortunately. show_404() (located in codeigniter.php) only loads the exceptions class to do the bare minimum to show the error.
#5

[eluser]CroNiX[/eluser]
A workaround I used for 1.7 days was to check for
if(function_exists('get_instance'))...then load ci with get_instance, else manually include CI and then use get_instance.
#6

[eluser]TexMax007[/eluser]
I was afraid of that. Thanks for the information.
#7

[eluser]CroNiX[/eluser]
I thought this was fixed using the 404_override? Or was that just for true 404's (controller/method not found) and not when you manually call show_404()?
#8

[eluser]TexMax007[/eluser]
I'm not sure I follow you on the if_exists thing.

I'm really new to CI, so I don't know.

As far as my case, I'm not calling show_404, this is for putting in the wrong controller/method.

Thanks.
#9

[eluser]vbsaltydog[/eluser]
Code:
$route['404_overrride'] = 'controller/method-to-handle-custom-404-error-page';
#10

[eluser]TexMax007[/eluser]
I must have missed your last post regarding the $route['404_override'] because I just came back to update that I had found that and it worked like a charm.

Thanks for making the suggestion; I wish I had seen that sooner lol.





Theme © iAndrew 2016 - Forum software by © MyBB