-
-
Save Flatroy/302cf74d645b44e8a699 to your computer and use it in GitHub Desktop.
Revisions
-
maid450 renamed this gist
Jul 10, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
maid450 renamed this gist
Jul 10, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
maid450 revised this gist
Feb 17, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ Auth::instance()->logged_in('admin') // for current user //Check whether some other user has a role // Load the role $role = ORM::factory('role', array('name' => 'admin')); // Check that the user has the given role $status = $user->has('roles', $role); -
maid450 revised this gist
Feb 17, 2012 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php //Useful code snippets //Here are some code snippets which show you the basics of Auth: @@ -37,4 +38,4 @@ $user->remove('roles', ORM::factory('role')->where('name', '=', 'admin')->find() // find all the reviewer users in order of their username $role = ORM::factory('role')->where('name', '=', 'reviewer')->find(); $users = $role->users->order_by('username', 'DESC')->find_all(); foreach($users as $user) {...} -
maid450 created this gist
Feb 17, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ //Useful code snippets //Here are some code snippets which show you the basics of Auth: //Create a new user (e.g. if you have not set up any users yet and want to do that programmatically) $model = ORM::factory('user'); $model->values(array( 'username' => 'admin', 'email' => '[email protected]', 'password' => 'admin', 'password_confirm' => 'admin', )); $model->save(); // remember to add the login role AND the admin role // add a role; add() executes the query immediately $model->add('roles', ORM::factory('role')->where('name', '=', 'login')->find()); $model->add('roles', ORM::factory('role')->where('name', '=', 'admin')->find()); //Check whether current user has a role Auth::instance()->logged_in('admin') // for current user //Check whether some other user has a role // Load the role $role = ORM::factory('role', array('name' => 'admin)); // Check that the user has the given role $status = $user->has('roles', $role); //Add a role to a user // add() executes the query immediately, and saves the data (unlike the KO2 docs say) $user->add('roles', ORM::factory('role')->where('name', '=', 'admin')->find()); //Remove a role from a user // remove() executes the query immediately $user->remove('roles', ORM::factory('role')->where('name', '=', 'admin')->find()); //Retrieve all users that have a particular role // find all the reviewer users in order of their username $role = ORM::factory('role')->where('name', '=', 'reviewer')->find(); $users = $role->users->order_by('username', 'DESC')->find_all(); foreach($users as $user) {...}