本文整理汇总了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');
}
}