I'm trying to prevent a method from executing if validation in constructor fails. I'm using AJAX and I'm sending the request to a url like example/search
. I'm currently checking if a variable isn't false but I think there's a better way of doing that, isn't there?
class Example extends CI_Controller {
public $error;
function __construct() {
parent::__construct();
//validation rules
if($this->form_validation->run() == FALSE) {
$this->error=1;
}
}
function search() {
if(!$this->error) {
//code
}
}
}