本文整理汇总了PHP中Roles::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::findFirst方法的具体用法?PHP Roles::findFirst怎么用?PHP Roles::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::findFirst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction($action = null, $role_id = null, $user_id = null)
{
// Add a user to a mailing list
if ($this->request->isPost()) {
$user_id = $this->request->getPost("user_id");
$role_id = $this->request->getPost("role_id");
if (!empty($user_id)) {
// If user and corresponding role already exist
if ($mail = PMailList::findFirst("role_id={$role_id} AND user_id={$user_id}")) {
$this->flash->error("Получатель уже существует");
} else {
$mail_list = new PMailList();
$mail_list->role_id = $role_id;
$mail_list->user_id = $user_id;
if ($mail_list->save()) {
$this->flash->success("Получатель добавлен");
}
}
return $this->response->redirect("mailer/index");
}
}
// Delete a user from a mailing list
if ($action == 'delete') {
if ($mail = PMailList::findFirst("role_id={$role_id} AND user_id={$user_id}")) {
if (!$mail->delete()) {
$this->flash->error("Произошла ошибка");
} else {
$this->flash->success("Получатель удален");
}
return $this->response->redirect("mailer/index");
}
}
// List of roles
foreach ($this->roles as $alias) {
$role = Roles::findFirst("alias='{$alias}'");
$roles[$role->id] = $role->name;
}
$this->view->roles = $roles;
// List of users subscribed
$list = [];
$all = PMailList::find();
foreach ($all as $one) {
$list[] = [$one->role_id => [$one->user_id => $one->Accounts->name]];
}
$this->view->list = $list;
}
示例2: get_all_permissions
public function get_all_permissions()
{
// $request = $this->get_request();
// $id_user = $request->id;
$id_user = 1;
$role_acos = array();
$user = Users::findFirst($id_user);
foreach ($user->RolesUsers as $rol_usuario) {
$roles = Roles::findFirst($rol_usuario->getIdRole());
foreach ($roles->RolesPermissions as $rol_permission) {
$role_acos[] = $rol_permission->Permissions->getIdAco();
}
}
$user_acos = array();
$user = Users::findFirst($id_user);
foreach ($user->UsersPermissions as $user_permission) {
$user_acos[] = $user_permission->Permissions->getIdAco();
}
$merge_permissions = array_merge($role_acos, $user_acos);
$result = array_unique($merge_permissions);
return $result;
}