Welcome Guest, Not a member yet? Register   Sign In
Change Error Function per Controller
#1

[eluser]artie11[/eluser]
I'd like to have a single controller's Error function routed through a function in the controller.

It's a JSON Interface Module, and i'd like the errors to be returned in a JSON format so they can be parsed
#2

[eluser]artie11[/eluser]
I've found a place to patch it, unless someone has a better idea,

However it's getting to be like 1am here, so my brain is slowly stopping,
Under system/codeigniter/common.php there's an error function, it could have a look at the current get string and work out if it needs to be passed back as a json error.

However as previously stated, my brain isn't working out the part about looking for which controller
#3

[eluser]artie11[/eluser]
Code:
<?
if (stripos($_SERVER['QUERY_STRING'],'json') == 0){echo json_encode(array('errors'=>array('Title'=>$heading,'Message'=>$message)));}else{
?>

This Code Inserted into each error page, will switch to the json output if you want, don't forget to change the search string in stripos

Solved
#4

[eluser]artie11[/eluser]
Code:
<?
if (stripos($_SERVER['QUERY_STRING'],'json/') != FALSE){echo json_encode(array('errors'=>array('Title'=>$heading,'Message'=>$message)));}else{
?>

More Testing, Fixed it more

any Comments appreciated




Theme © iAndrew 2016 - Forum software by © MyBB