Zend_Acl : Using a database for persistance, is it better to serialize the acl object or use a special schema?
I need to implement the Zend_Acl component. I read in the docs that the Zend_Acl object can be serialized with the serialized function of PHP. My application will have lots of roles, rules and resources. And I need to create a backend to configure all this stuff.
My question is: In this case, is it better to serialize the ACL object, or it's better to create a schema to persist roles, rules and resources in three different tables? My guess is the first option, because the Zend_Acl component already has methods to add开发者_开发百科 / remove rules, it handles itself the inheritance of each type of object and it has the possibility to query the ACL. But I would like to hear opinions from people who faced this situation before so I don't make a big mistake deciding without asking :)
Thanks!
You need to create the schema first no matter how big or complicated it gets, then implement Zend_Acl
by extending the class, override allow()
and deny()
methods and put your CRUD for the permission schema in them, and then pass the call to parent::allow()
and parent::deny()
, respectively.
Building the ACL will take time, but you can cache it using Zend_Cache
. Using this approach, your ACL will remain in sync with your schema.
I think this is mainly a question of which option is more suited to what you need.
The main considerations I think are as follows:
- ACL size: A very large ACL may not be very fast to serialize/unserialize, and it may work slower in general.
- ACL modification: Do you need to be able to perform more complicated modifications to the ACL than just maybe adding and removing rules
In the case of a large ACL, having a specific schema is a better option. This will allow you to easily construct the ACL of only the specific rules which apply to your current usage. This way you can limit the size of the ACL, and get better performance.
If have a small ACL, serialization will usually work quite well.
If you need to do more complicated changes to the ACL, you might also want to consider using a specific schema for it. This way you will have an easier time querying all the rules, and displaying them for the user to edit.
(Regarding the size / performance parts: You probably can just profile and see if you have performance issues to determine the best choice)
精彩评论