我有一个Cake网站,它需要有两个单独的登录,每个登录表单都会有自己的登录表单并且看到不同的页面,因此有两个不同的表格会很好,因为它们之间没有相似之处两种人。CakePHP 2个单独的登录表
每个登录表单只会被某些人使用,他们将永远不会登录到其他表单,反之亦然。
此外,两个登录表之间有一个关系,它需要2个表?
这可能吗?
我有一个Cake网站,它需要有两个单独的登录,每个登录表单都会有自己的登录表单并且看到不同的页面,因此有两个不同的表格会很好,因为它们之间没有相似之处两种人。CakePHP 2个单独的登录表
每个登录表单只会被某些人使用,他们将永远不会登录到其他表单,反之亦然。
此外,两个登录表之间有一个关系,它需要2个表?
这可能吗?
首先,添加几个空的自定义身份验证对象。我们将重用FormAuthenticate使用的相同逻辑(即使用POST数据为用户检查数据库),但只需在对象设置中更改模型(稍后)即可。
应用程序/控制器/组件/认证/ ModelOneAuthenticate.php
<?php
App::uses('FormAuthenticate', 'Controller/Component/Auth');
class ModelOneAuthenticate extends FormAuthenticate {
}
应用程序/控制器/组件/认证/ ModelTwoAuthenticate.php
<?php
App::uses('FormAuthenticate', 'Controller/Component/Auth');
class ModelTwoAuthenticate extends FormAuthenticate {
}
然后告诉您的应用程序使用这些对象进行身份验证,并告诉它使用什么模型。您也可以在此自定义字段。在你的AppController:
public $components = array(
'Auth' => array(
'authenticate' => array(
'ModelOne' => array(
'userModel' => 'ModelOne',
'fields' => array(
'username' => 'my_custom_username_field',
'password' => 'some_password_field'
)
),
'ModelTwo' => array(
'userModel' => 'ModelTwo'
)
)
)
);
第一认证对象将检查model_ones
表中my_custom_username_field
在some_password_field
用户名和密码,而第二个将使用标准username
和password
领域检查model_twos
。
感谢您的支持!到目前为止,我已经完成了所有的代码并没有错误,但是当我去一个受限制的页面时,它会尝试去用户/登录时,我已经说过要去代理/登录 - 唉想法为什么?这是我的:http://codepad.org/zvBeJFEX – 472084
你需要设置loginRedirect属性:http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html# AuthComponent :: $ loginRedirect – jeremyharris
我有这样的设置:http://codepad.org/zvBeJFEX - 我需要将它添加到新创建的auth类,而不是某种方式吗? – 472084
当他们必须登录时有相似性:两者都会要求它输入凭据,通常是用户名/电子邮件和密码。所以用户表和foo_profiles表和bar_profiles表也取决于用户类型。
如果你真的想用两个不同的表和他们的MVC堆栈,那么只需使用两个不同的控制器FooUsers和BarUsers,并在每个控制器内创建一个定制的登录方法。
我之前通过编写扩展自BaseAuthenticate的自定义身份验证组件来完成此操作。只要他们实现authenticate()方法,那么你就可以为每种不同类型的用户做任何你想做的事情。
在你的AppController你需要做类似
public $components = array(
"Session",
"Auth" => array(
'authenticate' => array("UserType1", "UserType2"),
)
);
退房的cookbook为它的其余部分进行注册的不同组件。
要做到这一点最简单的方法是只为每个登录类型不同的会话密钥:
if ($loginTypeOne) {
$this->Auth->authenticate = array(
'Form'=> array(
'userModel'=> 'TypeOne',
)
);
AuthComponent::$sessionKey = 'Auth.TypeOne';
} else {
$this->Auth->authenticate = array(
'Form'=> array(
'userModel'=> 'TypeTwo',
)
);
AuthComponent::$sessionKey = 'Auth.TypeTwo';
}
You can have a look on this.
Define Model for both login member and then define table which you want to use for the user.
set variable in model.
class SearchedCategory extends AppModel {
var $name = 'SearchedCategory';
Var useTable = 'give your table name here.';
var $primaryKey = 'id';
}
这看起来像什么,我需要但对于旧版本的蛋糕,说不定@deizel会看到这个:) – 472084
相同的概念,除了'identify'被移到了authenticate对象上,并被称为'authenticate'(或者''特别是'BaseAuthenticate'上的'_findUser'方法)。 – jeremyharris
所以,只要将'identify'改为'authenticate'? http://codepad.viper-7.com/1BX9fE – 472084