Welcome Guest, Not a member yet? Register   Sign In
Header/Footer at Error Message
#1

[eluser]hykoh[/eluser]
Hello,

is it possible to display the error msg with header/footer ?

for example:

Code:
<?php

if(1 != 2) {
show_error('1 is not 2');
}

?>

i want to display the message like:

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

<?=$errMsg;?>

$this->load->view('footer');

I already tried to modify the "error_general.php", but only get error that $this is not a object in this context.

Thanks for help
#2

[eluser]John_Betong[/eluser]
 
 
Try this in your Controller
Code:
<?php

    $data['errMsg'] = show_error('1 === 2'); // default to prevent undefined error message
    if(1 != 2) {
      $data['errMsg'] = show_error('1 is not 2');
    }

    $data['header' = $this->load->view('header', $data, TRUE); // see CI help on Loader Class
    $data['footer' = $this->load->view('footer', $data, TRUE); // see CI help on Loader Class

    $output = $this->load->view('header', $data, TRUE); // added $data
    echo $output;
  ?>
 
 
Your view
Code:
<html>
   <head>
     <title>Title goes here</title>
     <?= $header ?>
   </head>
   <body>
  
     <div>
       &lt;?=$errMsg;?&gt;
     </div>

     <div>
       &lt;?= $footer ?&gt;
     </div>

  &lt;/body&gt;
&lt;/html&gt;
&nbsp;
&nbsp;
&nbsp;
#3

[eluser]hykoh[/eluser]
it looks in any way ugly. isnt there any easier way to just include header/footer directly in the error_general.php ? should be always the same header/footer templates, only the error text changes
#4

[eluser]John_Betong[/eluser]
&nbsp;
My apologies, I did not understand exactly what you were after so I will try again.
&nbsp;
I am not sure how error_general.php but it does accept the $heading and $message variables.
&nbsp;
To achieve your result then what you could try is:
Code:
&lt;?php include_once($path .'..\..\views\_header.php') ?&gt;
  
   &lt;?php echo $message; ?&gt;

  &lt;?php include_once(..\..\views\_footer.php') ?&gt;
&nbsp;
You will have to play about with the paths to make sure they are correct.
&nbsp;
&nbsp;
#5

[eluser]hykoh[/eluser]
if it would be so easy - i had no problem ;-)


the problem with your solution is: normally, i have defined one main_model at autoload, which offers the needed variables for the menu for example in the header/footer itself. but if i just include these files, there's still no class instance you know ?
#6

[eluser]John_Betong[/eluser]
&nbsp;
I think what you are trying to do is far from straight forward and not easily available.
&nbsp;
Similar problems have arisen in the past with the error_404.php output.
&nbsp;
Try this thread : http://ellislab.com/forums/viewthread/81728/
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB