Let’s suppose there is a table user
id_user | name | id_state
1 | John | 2
and a table user_state
id_status | description
2 | User Active
using Codeigniter, what is the best way to do something related to that id_status, without having integer hardcoded in my code??
example:
if($user->id_status == 2){
// do something
}
..
actually i have used in other projects a class to create “enums”:
Enum::Create('UserState', 'inactive', 'active', 'banned', 'deleted');
and them..
echo UserState::GetDatabaseID(UserState::active); // result: 2
.. and i think it is a good solution, but i have never used it in a Codeigniter project
If this user_state table is small enough (i.e. < 10 states) I would consider just putting an array right down in your application. So define some high level property in your My_Model for instance that says:
Then later in your code you just use something like