Welcome Guest, Not a member yet? Register   Sign In
authorization function w/multiple failure values
#1

[eluser]Bacteria Man[/eluser]
I'm developing an authorization function which will return multiple failure values. In other words not just true/false.

To reduce overhead the query string includes a couple of left joins to return all the required data in one pass. If the foreign keys do not exist, the corresponding fields will equal null. Depending on which field is null will determine where the authorization fails.

In the past (using other platforms) I've devised a list of error codes. For example:

-100, that group does not exist
-200, you are already a member of this group
-300, you are not allowed to join this group

The function will return true if all of the conditions are satisfied.

There's nothing complicated about this, but what's the best way to about it using Code Igniter? Is there anything in the core that would make this more efficient and/or easier to implement?

Thanks in advance.
#2

[eluser]Phil Sturgeon[/eluser]
I'd reccomend a slightly more OOP solution. In your library have at the top:

Code:
var $error_no = 0;
var $error_str = '';

Then you can have:

Code:
if($this->library->check()):
echo "it worked!";
else:
echo "Error No: "$this->library->error_no."<br/>"
echo "Description: ".$this->library->error_str;
endif;

None of it makes a huge amount of difference really, theres just a possibility this might be a little easier and means the code is kept more modular as nothing outside the library itself needs to know what the error numbers are.
#3

[eluser]Bacteria Man[/eluser]
Thanks for your reply.

Yes, I like your OOP approach.

I ended up not going with my original error code idea and opted to break up the single query into separate ones, which provides more granular messaging. The overhead isn't an issue after all since the operation is only performed at specific times.




Theme © iAndrew 2016 - Forum software by © MyBB