本文整理汇总了PHP中Role::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::find方法的具体用法?PHP Role::find怎么用?PHP Role::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signup
/**
* Signup a new account with the given parameters
*
* @param array $input Array containing 'username', 'email' and 'password'.
*
* @return User User object that may or may not be saved successfully. Check the id to make sure.
*/
public function signup($input)
{
$user = new User();
$user->username = md5(uniqid(mt_rand(), true));
$user->email = array_get($input, 'email');
$user->password = array_get($input, 'password');
$myRole = array_get($input, 'myrole');
// The password confirmation will be removed from model
// before saving. This field will be used in Ardent's
// auto validation.
$user->password_confirmation = array_get($input, 'password_confirmation');
// Generate a random confirmation code
$user->confirmation_code = md5(uniqid(mt_rand(), true));
// Save if valid. Password field will be hashed before save
$user->save();
if ($GLOBALS['APP-MAILING'] == false) {
$user->confirmed = 1;
$user->save();
}
// Add Role
if ($user->id) {
$role = Role::find($myRole);
$user->roles()->attach($role);
}
return $user;
}
示例2: initialize
public function initialize($user, $role)
{
$this->add(new Text("userName", array('placeholder' => '*Nombre de usuario', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Password("pass", array('placeholder' => '*Contraseña', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Password("pass2", array('placeholder' => '*Repita la contraseña', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Email("email", array('placeholder' => '*Email', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Text("name_user", array('placeholder' => '*Nombre', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Text("lastName", array('placeholder' => '*Apellido', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Text("address_user", array('placeholder' => '*Dirección', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Select('state_user', array('' => '*Seleccionar Departamento', 'AMAZONAS' => 'AMAZONAS', 'ANTIOQUIA' => 'ANTIOQUIA', 'ARAUCA' => 'ARAUCA', 'ATLANTICO' => 'ATLANTICO', 'BOLIVAR' => 'BOLIVAR', 'BOYACA' => 'BOYACA', 'BOYACA' => 'BOYACA', 'CALDAS' => 'CALDAS', 'CAQUETA' => 'CAQUETA', 'CASANARE' => 'CASANARE', 'CAUCA' => 'CAUCA', 'CESAR' => 'CESAR', 'CHOCO' => 'CHOCO', 'CORDOBA' => 'CORDOBA', 'CUNDINAMARCA' => 'CUNDINAMARCA', 'GUAINIA' => 'GUAINIA', 'GUAJIRA' => 'GUAJIRA', 'GUAVIARE' => 'GUAVIARE', 'HUILA' => 'HUILA', 'MAGDALENA' => 'MAGDALENA', 'META' => 'META', 'NARIÑO' => 'NARIÑO', 'NTE_SANTANDER' => 'NORTE DE SANTANDER', 'PUTUMAYO' => 'PUTUMAYO', 'QUINDIO' => 'QUINDIO', 'RISARALDA' => 'RISARALDA', 'SAN_ANDRES' => 'SAN ANDRES Y PROVIDENCIA', 'SANTANDER' => 'SANTANDER', 'SUCRE' => 'SUCRE', 'TOLIMA' => 'TOLIMA', 'VALLE' => 'VALLE DEL CAUCA', 'VAUPES' => 'VAUPES', 'VICHADA' => 'VICHADA')));
$this->add(new Select('city_user', array()));
$this->add(new Text("phone_user", array('placeholder' => '*Teléfono', 'required' => 'required', 'class' => 'form-control')));
$roles = Role::find();
$r = array();
if ($role->name == 'sudo') {
foreach ($roles as $rol) {
$r[$rol->idRole] = $rol->name;
}
} else {
foreach ($roles as $rol) {
if ($rol->name != 'sudo') {
$r[$rol->idRole] = $rol->name;
}
}
}
$this->add(new Select('idRole', $r, array('placeholder' => '*Funciones', 'required' => 'required', 'class' => 'form-control select2')));
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$role = Role::find($id);
$role->name = Input::get('name');
$role->save();
return Redirect::route('roles.index');
}
示例4: getAcl
public function getAcl()
{
//if (!isset($this->persistent->acl)) {
$acl = new Phalcon\Acl\Adapter\Memory();
$acl->setDefaultAction(Phalcon\Acl::DENY);
//Register roles
$rol = Role::find(array("cache" => array("key" => "role")));
foreach ($rol as $ros) {
$roles[strtolower($ros->name)] = new Phalcon\Acl\Role($ros->name);
}
foreach ($roles as $role) {
$acl->addRole($role);
}
foreach (Action::find(array("cache" => array("key" => "action"))) as $actions) {
$acl->addResource(new Phalcon\Acl\Resource($actions->controller->name), $actions->name);
}
//Grant access to public areas to both users and guests
foreach ($rol as $role) {
foreach ($role->action as $action) {
$roledann[$role->name][$action->controller->name][] = $action->name;
}
}
// print_r($roledann);
foreach ($roledann as $keys => $dann) {
foreach ($dann as $key => $dan) {
$acl->allow($keys, $key, $dan);
}
}
//The acl is stored in session, APC would be useful here too
//$this->persistent->acl = $acl;
// }
//return $this->persistent->acl;
return $acl;
}
示例5: desasignar
public function desasignar()
{
$rol = Role::find(Input::get('role_id'));
$rolPermisos = RolesPermission::where('role_id', '=', Input::get('role_id'))->where('permission_id', '=', Input::get('permission_id'))->get()->first();
$desasignar = RolesPermission::destroy($rolPermisos->id);
return Response::json('ok');
}
示例6: initialize
public function initialize($user, $thuser)
{
$roles = Role::find();
$r = array();
if ($thuser->idRole == 1) {
foreach ($roles as $rol) {
$r[$rol->idRole] = $rol->name;
}
} else {
foreach ($roles as $rol) {
if ($rol->name != 'sudo') {
$r[$rol->idRole] = $rol->name;
}
}
}
$this->add(new Select('idRole', $r, array('required' => 'required', 'class' => 'select2 select')));
$this->add(new Check('status', array('type' => 'checkbox', 'class' => 'bootstrap-switch')));
$this->add(new Text('email', array('maxlength' => 100, 'type' => 'email', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Text('userName', array('maxlength' => 40, 'type' => 'text', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Password('password1', array('maxlength' => 50, 'type' => 'text', 'required' => 'password', 'class' => 'form-control')));
$this->add(new Password('password2', array('maxlength' => 50, 'type' => 'password', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Text('name', array('maxlength' => 40, 'type' => 'text', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Text('lastName', array('maxlength' => 40, 'type' => 'text', 'required' => 'required', 'class' => 'form-control')));
$this->add(new Text('phone', array('maxlength' => 50, 'type' => 'text', 'class' => 'form-control')));
}
示例7: store
/**
* Store a newly created resource in storage.
* POST /users
*
* @return Response
*/
public function store()
{
Input::merge(array_map('trim', Input::all()));
$input = Input::all();
$validation = Validator::make($input, User::$rules);
if ($validation->passes()) {
DB::transaction(function () {
$user = new User();
$user->first_name = strtoupper(Input::get('first_name'));
$user->middle_initial = strtoupper(Input::get('middle_initial'));
$user->last_name = strtoupper(Input::get('last_name'));
$user->dept_id = Input::get('department');
$user->confirmed = 1;
$user->active = 1;
$user->email = Input::get('email');
$user->username = Input::get('username');
$user->password = Input::get('password');
$user->password_confirmation = Input::get('password_confirmation');
$user->confirmation_code = md5(uniqid(mt_rand(), true));
$user->image = "default.png";
$user->save();
$role = Role::find(Input::get('name'));
$user->roles()->attach($role->id);
});
return Redirect::route('user.index')->with('class', 'success')->with('message', 'Record successfully added.');
} else {
return Redirect::route('user.create')->withInput(Input::except(array('password', 'password_confirmation')))->withErrors($validation)->with('class', 'error')->with('message', 'There were validation errors.');
}
}
示例8: destroy
public static function destroy($id)
{
$role = Role::find($id);
$role->destroy();
flash('Role removed successfully!');
Redirect::to('/roles');
}
示例9: run
public function run()
{
$faker = Faker::create();
Permission::truncate();
DB::table('permission_role')->truncate();
Permission::create(['action' => 'User.create']);
Permission::create(['action' => 'User.view']);
Permission::create(['action' => 'User.update']);
Permission::create(['action' => 'User.delete']);
Permission::create(['action' => 'Category.create']);
Permission::create(['action' => 'Category.view']);
Permission::create(['action' => 'Category.update']);
Permission::create(['action' => 'Category.delete']);
Permission::create(['action' => 'Post.create']);
Permission::create(['action' => 'Post.view']);
Permission::create(['action' => 'Post.update']);
Permission::create(['action' => 'Post.delete']);
Permission::create(['action' => 'Comment.create']);
Permission::create(['action' => 'Comment.view']);
Permission::create(['action' => 'Comment.update']);
Permission::create(['action' => 'Comment.delete']);
Permission::create(['action' => 'Role.create']);
Permission::create(['action' => 'Role.view']);
Permission::create(['action' => 'Role.update']);
Permission::create(['action' => 'Role.delete']);
Permission::create(['action' => 'Permission.create']);
Permission::create(['action' => 'Permission.view']);
Permission::create(['action' => 'Permission.update']);
Permission::create(['action' => 'Permission.delete']);
$admin = Role::find(1);
$admin->permissions()->sync(range(1, 24));
}
示例10: storeUser
public function storeUser()
{
$validator = Validator::make($data = Input::all(), User::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$user = new User();
$user->username = $data['username'];
$user->email = $data['email'];
$user->password = $data['password'];
$user->password_confirmation = $data['password_confirmation'];
if (isset($data['tipe'])) {
$user->tipe = $data['tipe'];
$user->nama = $data['nama'];
$user->alamat = $data['alamat'];
$user->telp = $data['telp'];
}
$user->confirmed = 1;
$user->save();
if ($data['role'] == '0') {
$user->attachRole(Role::find(6));
} elseif ($data['role'] == '1') {
$user->attachRole(Role::find(3));
} elseif ($data['role'] == '2') {
$user->attachRole(Role::find(4));
$outlet = new Outlet();
$outlet->user_id = $user->id;
$name = 'Outlet ' . $user->username . '';
$outlet->name = $name;
$outlet->save();
}
return Redirect::to('admin/users')->with('message', 'berhasil menambahkan user');
}
示例11: initialize
public function initialize($entity = null, $options = null)
{
$role = new Select('roleid', Role::find(), array('using' => array('id', 'role'), 'useEmpty' => TRUE, 'emptyText' => $this->di->get('translate')->_('Seleccione un Rol')));
$role->setLabel('Rol');
$this->add($role);
//añadimos un botón de tipo submit
$submit = $this->add(new Submit('Guardar', array('class' => 'btn btn-success')));
}
示例12: getRoleAttribute
public function getRoleAttribute()
{
if ($this->role_id == '0') {
return 'Няма';
} else {
return Role::find($this->role_id)->name;
}
}
示例13: find
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function find($id)
{
$model = Role::find($id);
if ($model) {
return $model;
}
return 'Role not found.';
}
示例14: delete
public function delete()
{
//check if the role already exist...
$id = Input::get('id');
$role = Role::find($id);
$role->delete();
return Response::jsend('success', array('msg' => 'Role successfully deleted.'));
}
示例15: delete
public function delete($id)
{
$role = Role::find($id);
$role->delete();
// redirect
Session::flash('message', 'Successfully deleted the role!');
return Redirect::to('admin/role');
}