本文整理汇总了PHP中app\models\User::hasPermission方法的典型用法代码示例。如果您正苦于以下问题:PHP User::hasPermission方法的具体用法?PHP User::hasPermission怎么用?PHP User::hasPermission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::hasPermission方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* @param User $user
* @param Document $document
* @return bool
*/
public static function view(User $user, $document)
{
if ($user->hasPermission('view_all')) {
return true;
}
if ($document->expense) {
if ($document->expense->invoice) {
return $user->can('view', $document->expense->invoice);
}
return $user->can('view', $document->expense);
}
if ($document->invoice) {
return $user->can('view', $document->invoice);
}
return $user->owns($item);
}
示例2: create
/**
* @param User $user
* @return bool
*/
public static function create(User $user, $item)
{
return $user->hasPermission('admin');
}
示例3: User
echo 1;
}
use app\models\Session;
use app\models\User;
use app\classes\DB;
$user = DB::connect();
if (Session::exists('home')) {
echo "<p><b>" . Session::flash('home') . "</b></p>";
}
$user = new User();
if ($user->isLoggedIn()) {
?>
<p>Hello, <a href="profile.php?user=<?php
echo escape($user->data()->username);
?>
"><?php
echo $user->data()->username;
?>
</a></p>
<ul>
<li>You can <a href="logout.php">log out</a> here!</li>
<li>You can <a href="update.php">update</a> your profile here!</li>
<li>You can <a href="changepassword.php">change password</a> here!</li>
</ul>
<?php
if ($user->hasPermission('admin')) {
echo 'You are an admin';
}
} else {
echo "<p>You need to <a href='login.php'>log in</a> or <a href='register.php'>register</a>!" . "</p>";
}
示例4: editByOwner
/**
* @param User $user
* @param $ownerUserId
* @return bool
*/
public static function editByOwner(User $user, $ownerUserId)
{
return $user->hasPermission('edit_all') || $user->id == $ownerUserId;
}
示例5: destroy
/**
* Determine if the given permission can be destroyed by the user.
*
* @param \App\User $user
* @param \App\Model\Permission $permission
* @return bool
*/
public function destroy(\App\Models\User $user, \App\Models\Permission $permission)
{
return $user->hasPermission('permission.destroy');
}
示例6: destroy
/**
* Determine if the given role can be destroyed by the user.
*
* @param \App\User $user
* @param \App\Model\Role $role
* @return bool
*/
public function destroy(\App\Models\User $user, \App\Models\Role $role)
{
return $user->hasPermission('role.destroy');
}