Php 使用Zend的隐私控制
我正在使用Zend制作一个社交网站。该网站允许用户成为朋友并访问彼此的个人资料和博客。我还希望用户能够控制他们的隐私,这可以采用参数“仅限好友”和“公开”。我查看了Zend_Acl,但它似乎只能处理单个用户的可访问性,而不是用户之间的关系。有什么好办法吗?出于您的目的,如果您使用Zend_Acl,您应该看看 考虑到应用程序中用户之间关系的复杂性,您将查询的大多数访问规则似乎都是动态的,因此它们在很大程度上依赖于可以使用更复杂逻辑来确定可访问性的断言 不过,您应该能够使用Zend_Acl实现您想要的功能 您可以像这样设置ACL规则:Php 使用Zend的隐私控制,php,zend-framework,Php,Zend Framework,我正在使用Zend制作一个社交网站。该网站允许用户成为朋友并访问彼此的个人资料和博客。我还希望用户能够控制他们的隐私,这可以采用参数“仅限好友”和“公开”。我查看了Zend_Acl,但它似乎只能处理单个用户的可访问性,而不是用户之间的关系。有什么好办法吗?出于您的目的,如果您使用Zend_Acl,您应该看看 考虑到应用程序中用户之间关系的复杂性,您将查询的大多数访问规则似乎都是动态的,因此它们在很大程度上依赖于可以使用更复杂逻辑来确定可访问性的断言 不过,您应该能够使用Zend_Acl实现您想要
$acl->allow('user', 'profile', 'view', new My_Acl_Assertion_UsersAreFriends());
ACL断言本身:
<?php
class My_Acl_Assertion_UsersAreFriends implements Zend_Acl_Assert_Interface
{
public function assert(Zend_Acl $acl,
Zend_Acl_Role_Interface $role = null,
Zend_Acl_Resource_Interface $resource = null,
$privilege = null)
{
return $this->_usersAreFriends();
}
protected function _usersAreFriends()
{
// get UserID of current logged in user
// assumes Zend_Auth has stored a User object of the logged in user
$user = Zend_Auth::getInstance()->getStorage();
$userId = $user->getId();
// get the ID of the user profile they are trying to view
// assume you can pull it from the URL
// or your controller or a plugin can set this value another way
$userToView = $this->getRequest()->getParam('id', null);
// call your function that checks the database for the friendship
$usersAreFriends = usersAreFriends($userId, $userToView);
return $usersAreFriends;
}
}
希望有帮助
if ($acl->isAllowed('user', 'profile', 'view')) {
// This will use the UsersAreFriends assertion
// they can view profile
} else {
// sorry, friend this person to view their profile
}