根据cakephp中的角色多次登录? [英] Multiple log in as per role in cakephp?

查看:87
本文介绍了根据cakephp中的角色多次登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CakePHP的新手。我试图创建多个登录不同的角色,如:学生,工作人员& admin



我已遵循这些教程:简单身份验证



管理员登录正在工作。



现在我想使用学生控制器创建学生登录&

 类AppController extends Controller {

public $ components = array(
' Session',
'Auth'=> array(
'loginRedirect'=> array('controller'=>'classes','action'=>'index'),
'logoutRedirect'=> array('controller'=>'users','action'=>'login')

);

function beforeFilter(){
if(isset($ this-> params ['admin'])){
$ this-> layout ='admin_default';
}
elseif(isset($ this-> params ['student'])){
$ this-> layout ='student_default';
}

$ this-> Auth-> allow('index','view');
}
}


谢谢。

解决方案

如果没有相应的学生模型,我不应该创建学生控制器。考虑您的请求,您可以实现类似此网址的



  / admin / users / login 
/ student / users / login
/ otherrole / users / login

php file:

 配置:: write('Routing.prefixes',array('admin')); 

并创建自定义操作...例如admin_login,student_login等...

检查此项=> http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing < =和(always)Happy Coding;)


I am new to CakePHP. I am trying to create multiple log in for different role like: student,staff & admin

I have followed these tutorial: Simple Authentication

admin log in is working currently.

now i want to create student log in using student controller & view.

class AppController extends Controller {

public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'classes', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
    )
);

  function beforeFilter(){
    if (isset($this->params['admin'])) { 
        $this->layout = 'admin_default';
    }
    elseif (isset($this->params['student'])){
        $this->layout = 'student_default';
    }

    $this->Auth->allow('index', 'view');
   }
 }

what should i do please help. Thank you.

解决方案

I guess you should not create a Students Controller if it have not a corresponding Student Model. Considering your request, you could implement something like this urls:

/admin/users/login
/student/users/login
/otherrole/users/login

just adding this to your config/core.php file:

Configure::write('Routing.prefixes', array('admin'));

and creating your custom actions... for example admin_login, student_login and so on...

Check this out => http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing <= and (always) Happy Coding ;)

这篇关于根据cakephp中的角色多次登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆