Cake PHP Auth 错误缺少数据库表。
我试图在我的项目中使用蛋糕教程中的 Cake PHP Auth 部分。但这不起作用。
我创建了三个表“admin_users”,其中包含字段(id,用户名,密码,group_id,创建,修改),“admin_groups”(id,名称,创建,修改)和“用户”(id,用户名,密码,创建,修改) );
我尝试将普通用户放入用户表中,而管理员用户则放入“admin_users”表中,并按“admin_groups”对管理员用户进行分组,以便在管理端进行权限访问。
当我尝试路径“[rootpath]/users/login”时,出现错误:未找到模型管理员的数据库表“admins”。但我没有为管理员创建模型。
在我再次手动创建 admins 表后,出现错误“未找到模型 UsersAdmin 的数据库表“users_admin””。这里也没有为UsersAdmin创建模型。
在用户控制器中
class UsersController extends AppController {
var $name = 'Users';
var $uses = array();
var $components = array('Auth','Session');
function login() {
$this->set('title_for_layout', 'Login');
/*if ($this->Auth->user()) {
$this->redirect($this->Auth->redirect());
}*/
}
function logout() {
$this->redirect($this->Auth->logout());
}
}
I was trying to work with Cake PHP Auth Section in cake tutorials with my project. But it doesn't work.
I have created three tables 'admin_users' with fields(id,username,password,group_id,created,modified) , 'admin_groups'(id,name,created, modified) and 'users'(id,username,password,created,modified);
I tried normal users will be put in users table and admin users are in 'admin_users' table and grouped the admin users by 'admin_groups' for permission acess in admin side.
When I try to path '[rootpath]/users/login' gives an error Database table 'admins' for model Admin was not found. But I dont created a model for admin.
After I maually created the admins table again error "Database table 'users_admin' for model UsersAdmin was not found". Here also dont created a model for UsersAdmin.
In Users Controller
class UsersController extends AppController {
var $name = 'Users';
var $uses = array();
var $components = array('Auth','Session');
function login() {
$this->set('title_for_layout', 'Login');
/*if ($this->Auth->user()) {
$this->redirect($this->Auth->redirect());
}*/
}
function logout() {
$this->redirect($this->Auth->logout());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题可能与您的数据库结构有关。
首先介绍一下主题,但是如果您从头开始您的项目,您可能应该只使用一个表(
users
)来存储所有用户,并将它们链接到另一个表(groups
) code>) 赋予他们不同的权利。它可以是与users
表中的字段group_id
的直接链接(这将允许您稍后使用核心 ACL 组件),也可以是与用户
和组
之间的表user_groups
。也就是说,Cake 无法立即理解一些内容:您将
admin_users
和admin_groups
之间的外键称为“group_id
” 。使用此名称,Cake 将尝试查找名为groups
的表,而不是admin_groups
。如果您想保留admin_groups
,则外键名称应为admin_group_id
。首先纠正这个问题,也许这会解决您遇到的一些问题。如果您未处于调试模式,您可能还需要更正 AdminUser 模型以反映此更新并清理缓存。
The problem is probably related to your database structure.
A bit of topic first, but if you start your project from scratch, you should probably use only one table (
users
) to store all users, and link them to another table (groups
) to give them different rights. It could be a direct link with a fieldgroup_id
in theusers
table (which will allow you later to use the core ACL component), or a many to many relation with a tableusers_groups
betweenusers
andgroups
.That said, there is something that Cake can't understand out of the box: you called the foreign key between
admin_users
andadmin_groups
"group_id
". With this name, Cake will try to find a table calledgroups
, notadmin_groups
. If you want to keep withadmin_groups
, the foreign key name should beadmin_group_id
.Correct this first, and maybe this will resolve some of the problems you get. You may also will have to correct the AdminUser model to reflect this update and clean the cache if you are not in debug mode.
尝试这样
Try like this