本文整理汇总了PHP中Access::set_roles方法的典型用法代码示例。如果您正苦于以下问题:PHP Access::set_roles方法的具体用法?PHP Access::set_roles怎么用?PHP Access::set_roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Access
的用法示例。
在下文中一共展示了Access::set_roles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: up
public function up()
{
//populate the system roles if they don't exist
if (\DBUtil::table_exists('roles')) {
if (\DB::count_records('roles') == 0) {
$roles = array(\Access::ROLE_ADMIN => 'Admin', \Access::ROLE_DEVELOPER => 'Developer', \Access::ROLE_EDITOR => 'Editor', \Access::ROLE_PENDING => 'Pending', \Access::ROLE_STANDARD => 'Standard', \Access::ROLE_SILVER => 'Silver', \Access::ROLE_GOLD => 'Gold', \Access::ROLE_DUMMY => 'Dummy');
foreach ($roles as $id => $role) {
\DB::insert('roles')->set(array('id' => $id, 'name' => strtolower($role), 'Description' => $role))->execute();
}
\Cli::write("\nPopulated roles.");
}
}
//create default admin user if we have no users
if (\DBUtil::table_exists('users')) {
if (\DB::count_records('users') == 0) {
//create the admin user
$data = array('username' => \Cli::prompt("Please enter an admin username"), 'email' => \Cli::prompt("Please enter an admin email"), 'password' => \Cli::prompt("Please enter an admin password"));
try {
$user = new \Warden\Model_User($data);
if (\Config::get('warden.confirmable.in_use') === true) {
$user->is_confirmed = true;
}
\Access::set_roles(array(\Access::ROLE_STANDARD, \Access::ROLE_ADMIN), $user);
//this will assign the roles and save the user
\Cli::write("\nCreated admin user.");
\Cli::write(\Cli::color("\nUsername : {$user->username}", 'blue'));
\Cli::write(\Cli::color("\nEmail : {$user->email}", 'blue'));
} catch (\Exception $e) {
\Cli::error("\n:( Failed to create admin user because: " . $e->getMessage());
}
}
}
//create the blog table if it doesnt exist
if (!\DBUtil::table_exists('blogs')) {
\DBUtil::create_table('blogs', array('id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true, 'auto_increment' => true), 'user_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true), 'title' => array('constraint' => 255, 'type' => 'varchar'), 'post' => array('type' => 'text'), 'publish_flag' => array('constraint' => 11, 'type' => 'int', 'default' => 0, 'unsigned' => true), 'public_flag' => array('constraint' => 11, 'type' => 'int', 'default' => 0, 'unsigned' => true), 'created_at' => array('type' => 'timestamp', 'default' => \DB::expr('CURRENT_TIMESTAMP')), 'updated_at' => array('type' => 'timestamp')), array('id'), true, 'InnoDB');
\DBUtil::create_index('blogs', 'user_id', 'user_id');
}
}
示例2: action_roles
public function action_roles($user_id = null)
{
if (empty($user_id)) {
$user_id = $this->user->id;
}
if (!\Access::can('assign_roles', $this->user)) {
//user must either be editing their own account, or have special privileges to edit someone else's
\Response::redirect('/welcome/404');
}
$post = \Input::post();
if (!empty($post)) {
$roles = empty($post['roles']) ? array() : $post['roles'];
try {
//load the user, assign the new roles and save
$user = $user_id == $this->user->id ? $this->user : \Warden\Model_User::find($user_id);
\Access::set_roles($roles, $user);
$user->save();
Session::set_flash('success', 'Successfully saved changes.');
} catch (\MongoOrm\ValidationFailed $ex) {
Session::set_flash('error', $ex->getMessage());
} catch (Exception $ex) {
$msg = $ex->getMessage();
Session::set_flash('error', $msg ? $msg : 'Oops, something went wrong.');
}
}
\Response::redirect('/member/view/' . $user_id);
}