- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 Social Engine 为站点开发模块,它使用 Zend 框架。我是 Zend Framework 和 Social Engine 的新手,但在 OOP 和 MVC 架构方面有经验,因此可以相对快速地掌握基础知识。
这是我正在开发的一个测试模块,所以刚刚构建了一个简单的模块,用户可以在其中创建、编辑或删除 CD 信息。然后有一个小部件,可以显示在他们喜欢的地方,显示 CD 信息。
我现在正处于需要设置人们可以看到哪些 CD 等权限的地步。所以我研究了其他模块,发现 Poll 模块是一个具体的例子。
查看其他模块后,我意识到当您创建某些内容时,它们会让用户手动设置权限。
因此将此代码添加到我的表单中以创建具有相关权限的选择框:
$auth = Engine_Api::_()->authorization()->context;
$user = Engine_Api::_()->user()->getViewer();
$viewOptions = (array) Engine_Api::_()->authorization()->getAdapter('levels')->getAllowed('ryan', $user, 'auth_view');
$viewOptions = array_intersect_key($availableLabels, array_flip($viewOptions));
$privacy = null;
if( !empty($viewOptions) && count($viewOptions) >= 1 ) {
// Make a hidden field
if(count($viewOptions) == 1) {
//$this->addElement('hidden', 'auth_view', array('value' => key($viewOptions)));
$privacy = new Zend_Form_Element_Hidden('auth_view');
$privacy->setValue(key($viewOptions));
// Make select box
} else {
$privacy = new Zend_Form_Element_Select('auth_view');
$privacy->setLabel('Privacy')
->setDescription('Who may see this CD?')
->setMultiOptions($viewOptions)
->setValue(key($viewOptions));
/*$this->addElement('Select', 'auth_view', array(
'label' => 'Privacy',
'description' => 'Who may see this CD?',
'multiOptions' => $viewOptions,
'value' => key($viewOptions),
));*/
}
}
$this->addElements(array($artist, $title, $privacy, $submit));
老实说,除了显然创建一个选择框并用指定的值填充它之外,我不完全确定这段代码的作用。
因此,如果用户选择“每个人”,每个人都应该能够删除和编辑该 CD,等等。
显然我认为 Controller 必须有一些代码来处理确定用户是否有权查看每张 cd 等。
所以扫描 Poll Controller 我发现这是在 Controller 的 init 函数中:
public function init() {
// Get subject
$poll = null;
if( null !== ($pollIdentity = $this->_getParam('poll_id')) ) {
$poll = Engine_Api::_()->getItem('poll', $pollIdentity);
if( null !== $poll ) {
Engine_Api::_()->core()->setSubject($poll);
}
}
// Get viewer
$this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
$this->view->viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();
// only show polls if authorized
$resource = ( $poll ? $poll : 'poll' );
$viewer = ( $viewer && $viewer->getIdentity() ? $viewer : null );
if( !$this->_helper->requireAuth()->setAuthParams($resource, $viewer, 'view')->isValid() ) {
return;
}
}
在顶部的每个操作中,它们都有一些不同的授权代码,一个这样的例子是 editAction
,它在顶部有这个代码:
// Check auth
if( !$this->_helper->requireUser()->isValid() ) {
return;
}
if( !$this->_helper->requireSubject()->isValid() ) {
return;
}
if( !$this->_helper->requireAuth()->setAuthParams(null, null, 'edit')->isValid() ) {
return;
}
在同一个 Action 中还有其他几个我不明白他们在做什么,下面是来自轮询 Controller 中 editAction
的随机片段:
$auth = Engine_Api::_()->authorization()->context;
$roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone');
// Populate form with current settings
$form->search->setValue($poll->search);
foreach( $roles as $role ) {
if( 1 === $auth->isAllowed($poll, $role, 'view') ) {
$form->auth_view->setValue($role);
}
if( 1 === $auth->isAllowed($poll, $role, 'comment') ) {
$form->auth_comment->setValue($role);
}
}
// CREATE AUTH STUFF HERE
if( empty($values['auth_view']) ) {
$values['auth_view'] = array('everyone');
}
if( empty($values['auth_comment']) ) {
$values['auth_comment'] = array('everyone');
}
$viewMax = array_search($values['auth_view'], $roles);
$commentMax = array_search($values['auth_comment'], $roles);
我的问题是,如果我 100% 诚实,我真的不太了解以上任何一项,在坐了几天并用谷歌搜索我的手指受伤后,我仍然不知道我是否真的有任何线索。是否可以为我解决以上任何问题,帮助向我解释事情,如果可能的话,我如何将我想要的权限应用到我的模块。
最佳答案
我将提供有关如何使用授权的简要说明,但需要通过查看 SocialEngine 的代码来推断更详细的信息。请注意,虽然我们不为 SocialEngine 编译文档,但我们的开发人员在我们的代码中使用了 PHPDocumentor 风格的语法,您可以使用像 Neatbeans (http://netbeans.org/) 这样的 IDE 来快速访问该信息。
SocialEngine 有一些 Controller Action 助手类,用于 Action Controller 中的查询授权:
在大多数情况下,您唯一关心的是这些:
可以在 Album_AlbumController 类中找到如何使用这些助手的一个很好的例子:应用程序/模块/Album/controllers/AlbumController.php
public function init()
{
if( !$this->_helper->requireAuth()->setAuthParams('album', null, 'view')->isValid() ) return;
if( 0 !== ($photo_id = (int) $this->_getParam('photo_id')) &&
null !== ($photo = Engine_Api::_()->getItem('album_photo', $photo_id)) )
{
Engine_Api::_()->core()->setSubject($photo);
}
else if( 0 !== ($album_id = (int) $this->_getParam('album_id')) &&
null !== ($album = Engine_Api::_()->getItem('album', $album_id)) )
{
Engine_Api::_()->core()->setSubject($album);
}
}
public function editAction()
{
if( !$this->_helper->requireUser()->isValid() ) return;
if( !$this->_helper->requireSubject('album')->isValid() ) return;
if( !$this->_helper->requireAuth()->setAuthParams(null, null, 'edit')->isValid() ) return;
init 函数中的代码简单地设置了访问页面的要求,然后在 editAction 函数中,检查授权数据。 requireSubject 和 requireUser 助手非常简单:
requireAuth 帮助程序不太直接。为了简洁起见,我将省略大部分抽象的内部工作。最后,helper 指向 Authorization_Api_Core::isAllowed 函数:应用程序/模块/授权/核心/Api.php
/**
* Gets the specified permission for the context
*
* @param Core_Model_Item_Abstract|string $resource The resource type or object that is being accessed
* @param Core_Model_Item_Abstract $role The item (user) performing the action
* @param string $action The name of the action being performed
* @return mixed 0/1 for allowed, or data for settings
*/
public function isAllowed($resource, $role, $action = 'view')
函数期望的 $resource 和 $role 对象是 Zend_Db_Table_Row 的实例,它在 SocialEngine 中被称为 Models 并且期望位于模块的 Models 目录中。调用 isAllowed 函数时,授权 API 将根据 engine4_authorization_allow、engine4_authorization_levels 和 engine4_authorization_permissions 表查询数据库。
应用程序/模块/授权/Api/Core.php
class Authorization_Api_Core extends Core_Api_Abstract
{
/**
* Constants
*/
const LEVEL_DISALLOW = 0;
const LEVEL_ALLOW = 1;
const LEVEL_MODERATE = 2;
const LEVEL_NONBOOLEAN = 3;
const LEVEL_IGNORE = 4;
const LEVEL_SERIALIZED = 5;
0) 不允许访问链接的资源。这与允许表中不存在的行相同
1) 也允许访问链接的资源
2) 允许访问和管理资源(即 super 管理员、管理员和版主成员级别)
3-5) 因不允许而被忽略。这些需要一些自定义逻辑才能适本地处理授权。
关于php - 了解用户权限以及如何应用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11520448/
我开始在 Ethereum blockchain 上了解如何开发智能合约以及如何写 web-script用于与智能合约交互(购买、销售、统计......)我得出了该怎么做的结论。我想知道我是否正确理解
我正在 UIView 中使用 CATransform3DMakeRotation,并且我正在尝试进行 45º,变换就像向后放置一样: 这是我拥有的“代码”,但显然没有这样做。 CATransform3
我目前正在测试 WebRTC 的功能,但我有一些脑逻辑问题。 WebRTC 究竟是什么? 我只读了“STUN”、“P2P”和其他...但是在技术方面什么是正确的 WebRTC(见下一个) 我需要什么
我在看 DelayedInit在 Scala in Depth ... 注释是我对代码的理解。 下面的 trait 接受一个非严格计算的参数(由于 => ),并返回 Unit .它的行为类似于构造函数
谁能给我指出一个用图片和简单的代码片段解释 WCF 的资源。我厌倦了谷歌搜索并在所有搜索结果中找到相同的“ABC”文章。 最佳答案 WCF 是一项非常复杂的技术,在我看来,它的文档记录非常少。启动和运
我期待以下 GetArgs.hs打印出传递给它的参数。 import System.Environment main = do args main 3 4 3 :39:1: Coul
private int vbo; private int ibo; vbo = glGenBuffers(); ibo = glGenBuffers(); glBindBuffer(GL_ARRAY_
我正在尝试一个 for 循环。我添加了一个 if 语句以在循环达到 30 时停止循环。 我见过i <= 10将运行 11 次,因为循环在达到 10 次时仍会运行。 如果有设置 i 的 if 语句,为什
我正在尝试了解 WSGI 的功能并需要一些帮助。 到目前为止,我知道它是一种服务器和应用程序之间的中间件,用于将不同的应用程序框架(位于服务器端)与应用程序连接,前提是相关框架具有 WSGI 适配器。
我是 Javascript 的新手,我正在尝试绕过 while 循环。我了解它们的目的,我想我了解它们的工作原理,但我在使用它们时遇到了麻烦。 我希望 while 值自身重复,直到两个随机数相互匹配。
我刚刚偶然发现Fabric并且文档并没有真正说明它是如何工作的。 我有根据的猜测是您需要在客户端和服务器端都安装它。 Python 代码存储在客户端,并在命令运行时通过 Fabric 的有线协议(pr
我想了解 ConditionalWeakTable .和有什么区别 class ClassA { static readonly ConditionalWeakTable OtherClass
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 5年前关闭。 Improve this questi
我还没有成功找到任何可以引导我理解 UIPickerView 和 UIPickerView 模型的好例子。有什么建议吗? 最佳答案 为什么不使用默认的 Apple 文档示例?这是来自苹果文档的名为 U
我在看foldM为了获得关于如何使用它的直觉。 foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a 在这个简单的例子中,我只返回 [Just
答案What are _mm_prefetch() locality hints?详细说明提示的含义。 我的问题是:我想要哪一个? 我正在处理一个被重复调用数十亿次的函数,其中包含一些 int 参数。
我一直在读这个article了解 gcroot 模板。我明白 gcroot provides handles into the garbage collected heap 然后 the handle
提供了一个用例: 流处理架构;事件进入 Kafka,然后由带有 MongoDB 接收器的作业进行处理。 数据库名称:myWebsite集合:用户 并且作业接收 users 集合中的 user 记录。
你好 我想更详细地了解 NFS 文件系统。我偶然发现了《NFS 图解》这本书,不幸的是它只能作为谷歌图书提供,所以有些页面丢失了。有人可能有另一个很好的资源,这将是在较低级别上了解 NFS 的良好开始
我无法理解这个问题,哪个更随机? rand() 或: rand() * rand() 我发现这是一个真正的脑筋急转弯,你能帮我吗? 编辑: 凭直觉,我知道数学答案是它们同样随机,但我忍不住认为,如果您
我是一名优秀的程序员,十分优秀!