当前位置: 首页>>代码示例>>PHP>>正文


PHP Access::set_roles方法代码示例

本文整理汇总了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');
     }
 }
开发者ID:jkapelner,项目名称:chatroom-web-server,代码行数:38,代码来源:001_create_tables.php

示例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);
 }
开发者ID:jkapelner,项目名称:chatroom-web-server,代码行数:27,代码来源:member.php


注:本文中的Access::set_roles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。