1146 Table 在 Cakephp 3 中的自定义 table 名称中不存在

1146 Table doesn't exist on custom table name in Cakephp 3

版本 CakePHP v3.4.7

QLSTATE[42S02]: Base table or view not found: 1146 Table 'DB.notifications' doesn't exist

我有我的 table 西班牙文名字,我想使用我的模型和我的控制器的英文。

进入我的 NotificationsTable class 我已经设置了以下行:

$this->table('notificaciones');

所以我认为这就足够了,我可以使用其他名称。

这是我的 NotificationsTable

class NotificationsTable extends Table
{

    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('notificaciones');
        $this->primaryKey('notificaciones_id');

    }

    public function validationDefault(Validator $validator)
    {
        $validator
            ->add('notificaciones_id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('notificaciones_id', 'create');


        return $validator;
    }

    public function buildRules(RulesChecker $rules)
    {
        $rules->add($rules->existsIn(['cola_id'], 'Colas'));

        return $rules;
    }
}

这是我的控制器:

class NotificationsController extends AppController
{

    public function index()
    {

        $this->paginate['contain'] = ['Colas'];
        $notifications = $this->paginate($this->Notifications);

        $this->set(compact('notifications'));
        $this->set('_serialize', ['notifications']);
    }
}

我以为只是设置

$this->table('notificaciones'); 

这就足够了,我可以使用另一个模型和控制器名称,而不是与我的 table 相同的名称。

有人知道发生了什么事吗?

我解决了问题!

它在命名空间上。我有:

namespace App\Model\Notification;

而不是:

namespace App\Model\Table;

写得不错!