本文整理汇总了PHP中UserRole::table方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRole::table方法的具体用法?PHP UserRole::table怎么用?PHP UserRole::table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRole
的用法示例。
在下文中一共展示了UserRole::table方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public function update()
{
if (!$this->has_post()) {
return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
}
$posts = OAInput::post();
if ($msg = $this->_validation_posts($posts)) {
return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts));
}
if ($columns = array_intersect_key($posts, $this->user->table()->columns)) {
foreach ($columns as $column => $value) {
$this->user->{$column} = $value;
}
}
$user = $this->user;
$update = user::transaction(function () use($user) {
return $user->save();
});
if (!$update) {
return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts));
}
$ori_keys = column_array($user->roles, 'name');
if (($del_keys = array_diff($ori_keys, $posts['roles'])) && ($roles = UserRole::find('all', array('select' => 'id', 'conditions' => array('user_id = ? AND name IN (?)', $user->id, $del_keys))))) {
foreach ($roles as $role) {
UserRole::transaction(function () use($role) {
return $role->destroy();
});
}
}
if ($add_keys = array_diff($posts['roles'], $ori_keys)) {
foreach ($add_keys as $add_key) {
UserRole::transaction(function () use($add_key, $user) {
return verifyCreateOrm(UserRole::create(Array_intersect_key(array('name' => $add_key, 'user_id' => $user->id), UserRole::table()->columns)));
});
}
}
return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '更新成功!'));
}