开发者

Cakephp:: Get data from others table?

I have this model called User, this model use "Users" table. This model is specially designed for admin to login. This model has "id, username, pa开发者_如何学Gossword, created, modified" fields.

Now, If I want to add more users, "normal users", users that can't login. What should I do?

Currently, I created new model called "Person", use "people" table, which has "id, username, email" fields.

From my admin panel(User model), how do I view the normal users(person model) data?


first, you are talking about authentication and authorization, you can check out the built-in acl and auth in cakephp.

second, to use Person model

$personModel = ClassRegistry::init('Person');
$person = $personModel->findById($id);


The classic way to handle this is to store all people in the users table and then add a group_id foreign key to link to the Groups table. Your groups table then has 1, Admin and 2, Normal User as the groups.

So your users table would look like this

users
-----
id, username, password, group_id, created, modified

and groups

groups
------
id, name

Link up your Users model to your Groups model with a belongsTo relationship

var $belongsTo = array('Group');

Now in your admin page you can see each type of user and tell if they are admin users or normal users with a simple fetch, or you can filter by group which group you want to look at.

This also plays really nicely if you are utilizing ACL component to handle access to your app. http://book.cakephp.org/view/1242/Access-Control-Lists

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜