问题描述
使用 AuthComponent::allowedActions 和 AuthComponent::allow 有什么区别?当我谷歌时,我看到大多数使用或谈论 allow() 的示例和文档,但只有少数使用 allowedActions.但它们的用法似乎很相似.
What is the difference between using AuthComponent::allowedActions and AuthComponent::allow?When I Google, I see the majority of examples and documents using or talking about allow(), but only a few using allowedActions. But they both seem similar in usage.
推荐答案
allowedActions 是一个包含允许操作列表的属性.
allowedActions is a property that contains a list of allowed actions.
allow() 是一种向 allowedActions 属性添加操作的方法.
allow() is a method that adds actions to the allowedActions property.
当您调用 allow() 方法时,它会将您指定的操作与已保存在 allowedActions 中的操作合并.
When you call the allow() method, it will merge the actions you specify with the actions already kept in allowedActions.
您可以绕过 allow() 方法并直接将一组允许的操作分配给 allowedActions 属性,但只有当我绝对必须覆盖以前添加的任何操作(例如,通过父类)时,我才会这样做这个性质.官方文档没有提到 allowedActions 属性.
You can bypass the allow() method and assign an array of allowed actions to the allowedActions property directly, but I would only do that if I absolutely had to override any actions previously added (for example, by a parent class) to this property. The official documentation makes no reference to the allowedActions property.
这篇关于AuthComponent:allowedActions 和allow() 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!