我正在使用cakephp3。我想制作登录页面。会计数据库中表的名称是'用户'。1146表'Accounting.users'不存在Cake Database
这是我的代码:
<?php
namespace App\Controller;
use App\Controller\AppController;
class UsersController extends AppController {
public function login() {
if ($this->request->is('post')) {
$data = $this->request->data;
$cnt = $data->Users->find()
->count();
if ($cnt > 0) {
$this->redirect(['action' => 'index']);
} else {
$this->set('error', 'username or password is incorrct ');
}
}
}}
,这是Users.php
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class UsersTable extends Table {
}
登录后在登录页面:
Error: Call to a member function find() on a non-object
在您看来,是什么问题。
只要看看你指的是'Users'的变量。我建议使用具有适当代码检查功能的IDE来标记此类错误。另外CakePHP附带一个认证层,您应该使用它。 – ndm