---
# System prepended metadata

title: Yii User
tags: [user, PHP, Yii, framework]

---

# Yii User

## 定義一個golbal function
```php
function getUser()
{
    return Yii::app()->user;
}
```

- 在其他地方就可以調用 getUser function
```
// 獲取user_id
getUser->id;
// 獲取username
getUser()->username;
```

###### tags: `Yii` `PHP` `framework` `user`