[eluser]the real rlee[/eluser]
For anyone referring to this thread here's how i created my custom error:
Extended Exceptions Library (My_Exceptions) (CI uses this to create its own global show_error(), show_404() functions)
Code:
class MY_Exceptions extends CI_Exceptions {
function MY_Exceptions(){
parent::CI_Exceptions();
}
function show_401()
{
$heading = "401 Not Authorized";
$message = "You are not authorized to view this page.";
echo $this->show_error($heading, $message, 'error_401');
exit;
}
}
Created a helper (helpers/error_helper.php) for my custom function which i autoload (CI does this within CodeIgniter/Common)
Code:
function show_401(){
$exceptions =& load_class('Exceptions');
$exceptions->show_401();
}
Created by own errors page (applications/errors/error_401.php)
Code:
<?php header("HTTP/1.1 401 Unauthorized"); ?>
<html>
<head>
<title>401 Unauthorized</title>
<style type="text/css">
body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 12px;
color: #000;
}
#content {
border: #999 1px solid;
background-color: #fff;
padding: 20px 20px 12px 20px;
}
h1 {
font-weight: normal;
font-size: 14px;
color: #990000;
margin: 0 0 4px 0;
}
</style>
</head>
<body>
<div id="content">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
<p><?=anchor('user/login', 'Please login to continue')?></p>
</div>
</body>
</html>
And hey presto (example usage):
Code:
Admin extends Controller {
function admin(){
parent::Controller();
if (!$this->user_auth->is_logged_in()) {
show_401();
}
}
}