• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
authorization function w/multiple failure values

[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.

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

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

Then you can have:

echo "it worked!";
echo "Error No: "$this->library->error_no."<br/>"
echo "Description: ".$this->library->error_str;

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.

[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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.