Gc\User\Model::fromId PHP Метод

fromId() публичный статический Метод

Initiliaze from id
public static fromId ( integer $userId ) : Model
$userId integer User id
Результат Model
    public static function fromId($userId)
    {
        $userTable = new Model();
        $row = $userTable->fetchRow($userTable->select(array('id' => (int) $userId)));
        $userTable->events()->trigger(__CLASS__, 'before.load', $userTable);
        if (!empty($row)) {
            $userTable->setData((array) $row);
            $userTable->unsetData('password');
            $userTable->setOrigData();
            $userTable->events()->trigger(__CLASS__, 'after.load', $userTable);
            return $userTable;
        } else {
            $userTable->events()->trigger(__CLASS__, 'after.load.failed', $userTable);
            return false;
        }
    }

Usage Example

Пример #1
0
 /**
  * Get user model
  *
  * @return \Gc\User\Model
  */
 public function getUser()
 {
     if ($this->getData('user') === null and $this->getUserId() != null) {
         $this->setData('user', User\Model::fromId($this->getUserId()));
     }
     return $this->getData('user');
 }
All Usage Examples Of Gc\User\Model::fromId