Welcome Guest, Not a member yet? Register   Sign In
DRY approach with different request type
#5

(This post was last modified: 10-18-2016, 06:44 AM by dave friend.)

Assuming you always want to reject AJAX requests this should work.
It responds to any AJAX request with an "Internal Server Error"

PHP Code:
function check_failed()
{
 if(
is_ajax_request())
 {
 
$this->output
 
->set_status_header(500)
 ->
set_header("Content-Type: text/plain")
 ->
set_output("Internal Server Error")
 ->
_display();
 exit();
 }
 elseif(
check_condition_failed)
 {
 
redirect(); // or show_404
 
}


And you will be much more DRY by putting this in a "base" controller that will be extended by the "Class#" controllers.
Reply


Messages In This Thread
RE: DRY approach with different request type - by dave friend - 10-18-2016, 06:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB