getId() public method

Returns a value that uniquely represents the user.
See also: getIdentity()
public getId ( ) : string | integer
return string | integer the unique identifier for the user. If `null`, it means the user is a guest.
コード例 #1
0
 /**
  * @param string $default
  *
  * @return string
  */
 protected function getIdentifier($default)
 {
     $id = $default;
     if ($this->user instanceof User && !$this->user->getIsGuest()) {
         $id = $this->user->getId();
     }
     return $id;
 }
コード例 #2
0
 /**
  * Returns true if $user can edit secure options for concrete entity ($owner).
  * @param User $user
  * @return bool
  */
 public function checkSecureAccess(User $user)
 {
     Yii::trace("Checking secure access to '{$this->owner->className()}'" . PHP_EOL . 'Identifier: ' . VarDumper::dumpAsString($this->owner->getPrimaryKey(true)) . PHP_EOL . "User: {$user->getId()}", __METHOD__);
     if (($identity = $user->getIdentity()) && $identity->isAdmin) {
         return true;
     }
     if (empty($this->secureRoles)) {
         return false;
     }
     foreach ($this->secureRoles as $item) {
         if (!$user->can($item)) {
             return false;
         }
     }
     return true;
 }