Welcome Guest, Not a member yet? Register   Sign In
Centralizing user-defined error.
#1

Hi,

I'm building software using of course CI and I want to make my user-defined errors centralized. I tried creating class extending from CI_Model and that class is base class of my other classes. That base class extending from CI_Model is located in the core dir. Though it works very well but I'm worried it's not a best practice? If not what can you suggest instead? Please give me insights. Here's my sample code.

class baseClass2 extends CI_Model {

const ERRORNO_EMPTY_VALUE = 4;
const ERRORSTR_EMPTY_VALUE = "Data should not be empty string.";

const ERRORNO_INVALID_PARAMETER = 8;
const ERRORSTR_INVALID_PARAMETER = "Invalid passed parameter.";

const ERRORNO_DB_VALUE_EXISTS = 9;
const ERRORSTR_DB_VALUE_EXISTS = "Database value already exist.";

public function __construct() {
parent::__construct();
}

protected function checkArrayKeyExists(array $needles, array $haystack) {
foreach ($needles as $needle) {
if ( ! array_key_exists($needle, $haystack)) {
error_log(self::ERRORNO_INVALID_PARAMETER . ": " . self::ERRORSTR_INVALID_PARAMETER . " '$needle' ");
return false;
}
}

return true;
}
}


and in my controller dir

class Company_model extends baseClass2 {

}


Thanks,
Reply


Messages In This Thread
Centralizing user-defined error. - by microzonebitzzz - 06-19-2015, 11:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB