Cakephp:: 从其他表中获取数据?
我有一个名为 User 的模型,该模型使用“Users”表。该模型是专门为管理员登录而设计的。该模型具有“id、用户名、密码、创建、修改”字段。
现在,如果我想添加更多用户,“普通用户”,无法登录的用户。我应该怎么办?
目前,我创建了名为“Person”的新模型,使用“people”表,其中包含“id、用户名、电子邮件”字段。
从我的管理面板(用户模型)中,如何查看普通用户(人员模型)数据?
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, password, 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您正在谈论身份验证和授权,您可以查看内置的 acl 和 cakephp 中的 auth。
二、使用Person模型
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
处理此问题的经典方法是将所有人员存储在 users 表中,然后添加一个 group_id 外键来链接到 Groups 表。您的组表中的组为 1(管理员)和 2(普通用户)。
因此,您的用户表将如下所示,
并且组
通过“belongsTo”关系将您的“用户”模型链接到“组”模型
现在,在您的管理页面中,您可以看到每种类型的用户,并通过简单的获取来判断他们是管理员用户还是普通用户,或者您可以按组过滤您想要查看的组。
如果您使用 ACL 组件来处理对应用程序的访问,这也非常有用。 http://book.cakephp.org/view/1242/Access-Control-Lists
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
and groups
Link up your Users model to your Groups model with a belongsTo relationship
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