本文整理匯總了PHP中Model\User::find_by_id方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::find_by_id方法的具體用法?PHP User::find_by_id怎麽用?PHP User::find_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Model\User
的用法示例。
在下文中一共展示了User::find_by_id方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
public function __construct()
{
if (isset($_SESSION['user'])) {
self::$storage = json_decode($_SESSION['user']);
} else {
if (isset($_COOKIE['sesskey'])) {
$sess = \Model\UserSession::find_by_sesskey($_COOKIE['sesskey']);
if ($sess) {
$user = \Model\User::find_by_id($sess->userid);
self::set($user->to_json());
}
}
}
}
示例2: edit
function edit($id)
{
// user_id
$app = get_app();
$user = User::find_by_id($id);
// GEt
if ($app->request()->isGet()) {
render_with_layout('misc.php', 'Users/edit.php', compact('user'));
}
// POST
if ($app->request()->isPost()) {
$post = $app->request()->post();
//
$user->account = $post['account'];
$user->username = $post['username'];
$user->group_id = $post['group_id'];
$user->role_id = $post['role_id'];
//
$password_1 = $post['password_1'];
$password_2 = $post['password_2'];
// 當滿足兩次輸入密碼相同 且 密碼長度大於8位
// 才更新密碼
if ($password_1 == $password_2 && strlen($password_1) >= 8) {
$user->password = md5($password_1);
} else {
$app->flashNow('errors', array('用戶密碼必須不小於8位!'));
render_with_layout('misc.php', 'Users/edit.php', compact('user'));
exit;
}
if (!$user->is_valid()) {
$app->flashNow('errors', $user->errrors);
render_with_layout('misc.php', 'Users/edit.php', compact('user'));
} else {
$user->save();
$app->flash('success', '用戶信息更新成功!');
redirect('/users');
}
}
}
示例3: profile
function profile()
{
$app = get_app();
$user = User::find_by_id($_SESSION['user_id']);
//GET
if ($app->request()->isGet()) {
render_with_layout('misc.php', 'Misc/profile.php');
}
//POST
if ($app->request()->isPost()) {
$post = $app->request()->post();
$old_pwd = $post['password'];
$new_pwd_1 = $post['new_pwd_1'];
$new_pwd_2 = $post['new_pwd_2'];
if (empty($old_pwd)) {
$app->flashNow('errors', array('當前密碼不能為空!'));
//render_with_layout('misc.php','Staffs/profile.php');
} else {
if (empty($new_pwd_1)) {
$app->flashNow('errors', array('新密碼不能為空!'));
} else {
if ($new_pwd_1 != $new_pwd_2) {
$app->flashNow('errors', array('兩次輸入的密碼不一致!'));
} else {
// set password
if (md5($old_pwd) != $user->password) {
$app->flashNow('errors', array('當前密碼錯誤,密碼更新失敗!'));
} else {
$user->password = md5($new_pwd_1);
$user->save();
$app->flashNow('success', '密碼更新成功!');
}
}
}
}
render_with_layout('misc.php', 'Misc/profile.php');
}
}