gpt4 book ai didi

php - Cakephp 登录页面要求表用户,但我只有一个用户表

转载 作者:行者123 更新时间:2023-11-28 23:40:11 24 4
gpt4 key购买 nike

我正在学习 Cakephp 3.0 的蛋糕教程

我在我想做登录页面的部分。我有一个名为 medical_wear 的数据库和一个表 user

当我在登录页面上输入我的电子邮件和密码时,出现以下错误:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'medical_wear.users' doesn't exist Please try correcting the issue for the following table aliases: Users

我不明白我没有 Users 表,我也没有在代码中使用 Users 表。

我搜索了很多主题和文档,但一无所获。

我在 src/Controller/AppController.php 中有这个

public function initialize() {
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'User',
'action' => 'login'
]
]);
// Autorise l'action display pour que notre controller de pages // continue de fonctionner.
$this->Auth->allow(['display']);
}

在 src/Controller/UsersController.php 中

public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Votre username ou mot de passe est incorrect.');
}
}

在 src/Template/Users/login.ctp

<h1>Connexion</h1>
<?= $this->Form->create() ?>
<?= $this->Form->input('email') ?>
<?= $this->Form->input('password') ?>
<?= $this->Form->button('Login') ?>
<?= $this->Form->end() ?>

最佳答案

cakephp 遵循命名约定

数据库表和字段命名约定

  1. 表名必须是小写和复数形式。如果有多个表名中的单词,然后单词应该用下划线分隔。

    Example : users, consultant_services, etc.
  2. Field-Name 也应该是小写的,如果超过一个单词然后用下划线分隔。

    Example : id, consultant_service_name
  3. ForeignKey 名称应该是单数和 tablename_id

    Example : users_id or consultant_services_id

模型命名约定

  1. 模型文件名是大写的驼峰字母,一个以上的单词应该是下划线分隔。

    Example : User.php or Consultant_service.php
  2. 模型类名是单数,一般应该是数据库表名,但采用单数格式。

    Example : User or ConsultantService

所以你的代码应该是

class UserTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('user');
}
}

更多信息conventions

关于php - Cakephp 登录页面要求表用户,但我只有一个用户表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34597237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com