本文整理汇总了PHP中UserRole::create方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRole::create方法的具体用法?PHP UserRole::create怎么用?PHP UserRole::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRole
的用法示例。
在下文中一共展示了UserRole::create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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' => '更新成功!'));
}
示例2: Create
public static function Create($userRole)
{
UserRole::create(['user_id' => $userRole->user_id, 'role_id' => $userRole->role_id]);
}
示例3: createDefaultData
public function createDefaultData()
{
Area::create(array('name' => 'Todas las áreas', 'company_id' => $this->id));
ProtocolCategory::create(array('name' => 'Todas los Protocolos', 'company_id' => $this->id));
UserRole::create(array('name' => 'Perfil general', 'company_id' => $this->id));
return true;
}