cakephp 4 找不到查找器方法

问题描述 投票:0回答:1

我的 CarsTable.php 中有一个名为“findActive”的查找方法,我从另一个控制器调用它:VehiclesController.php:

汽车表.php

    public function findActive(Query $query, array $options): Query
       { ..... }

// 控制器 VehiclesController.php

 $carsTable = TableRegistry::getTableLocator()->get('cars');
 $activeCars = $carsTable->find('active');

在我将其迁移到 cake 4 之前,它运行良好。有线索吗?

cakephp cakephp-4.x
1个回答
0
投票

尝试以下方法

  • 用 CamelCase 编写模型:TableRegistry::getTableLocator()->get('cars') -> TableRegistry::getTableLocator()->get('Cars')
  • 检查命名空间、.php 文件扩展名和文件位置是否正确。
  • 检查 findActive 中的查询是否正确(我认为是这样) - 签名看起来不错
© www.soinside.com 2019 - 2024. All rights reserved.