當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserRole::setUserId方法代碼示例

本文整理匯總了PHP中UserRole::setUserId方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserRole::setUserId方法的具體用法?PHP UserRole::setUserId怎麽用?PHP UserRole::setUserId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UserRole的用法示例。


在下文中一共展示了UserRole::setUserId方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: executeAddMember

 public function executeAddMember()
 {
     $this->validAjaxRequest();
     $ajax = new \AjaxResponse();
     if (!$this->isAllowed(PERMISSION_ROLE_PERMISSION_MANAGE)) {
         $ajax->type = \AjaxResponse::ERROR;
         $ajax->message = t("You do not have permission fot this action");
         return $this->renderText($ajax->toString());
     }
     $user_id = $this->post('user_id', 'INT', 0);
     if (!$user_id || !($user = \Users::retrieveById($user_id))) {
         $ajax->type = \AjaxResponse::ERROR;
         $ajax->message = t("User not found");
         return $this->renderText($ajax->toString());
     }
     $role_id = $this->post('role_id', 'INT', 0);
     if (!$role_id || !($role = \Roles::retrieveById($role_id))) {
         $ajax->type = \AjaxResponse::ERROR;
         $ajax->message = t("Role not found");
         return $this->renderText($ajax->toString());
     }
     if (\Users::SECTION_STAFF != $user->getSection()) {
         $ajax->type = \AjaxResponse::ERROR;
         $ajax->message = t("User %username% is not staff", array("%username%" => $user->getUsername()));
         return $this->renderText($ajax->toString());
     }
     if (!($userRole = \UserRole::findOneByRoleIdAndUserId($role->getId(), $user->getId()))) {
         $userRole = new \UserRole();
         $userRole->setRoleId($role->getId());
         $userRole->setUserId($user->getId());
         if ($userRole->save()) {
             $role->setMemberNo($role->getMemberNo() + 1);
             $role->save(false);
         }
     }
     $ajax->type = \AjaxResponse::SUCCESS;
     $ajax->message = t("Add member successful!");
     $ajax->user = $user->toArray();
     $ajax->role = $role->toArray();
     return $this->renderText($ajax->toString());
 }
開發者ID:hosivan90,項目名稱:toxotes,代碼行數:41,代碼來源:Role.php


注:本文中的UserRole::setUserId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。