在cakephp4中,如何访问模型中的模型

在cakephp4中,如何访问模型中的模型,cakephp,cakephp-3.0,cakephp-4.x,Cakephp,Cakephp 3.0,Cakephp 4.x,如何访问cakephp4.2中模型中的另一个模型?关于这个问题的文档我不清楚,然后我可以对此进行查询吗?现在不推荐使用TableRegistry error Unknown method "getTableLocator" called on App\Model\Table\LessonsTable //none of these no longer work in model { use Cake\ORM\Locator\LocatorAwareTrait;

如何访问cakephp4.2中模型中的另一个模型?关于这个问题的文档我不清楚,然后我可以对此进行查询吗?现在不推荐使用TableRegistry

 error Unknown method "getTableLocator" called on App\Model\Table\LessonsTable  

//none of these no longer work
in model {

use Cake\ORM\Locator\LocatorAwareTrait;


class LessonsTable extends Table
 {
 ..

  private function  getlessonRevenue(){

  //$clients = $this->getTableLocator()->get('Clients');
  // $cleints = TableRegistry::get('Clients'); 
  // $this->Table = TableRegistry::get('Clients');
   $clients = $this->getTableLocator()->get('Clients');
试试:

<?php
use Cake\ORM\Locator\LocatorAwareTrait; //<------------ add here
class ArchivesTable extends Table
{
  use LocatorAwareTrait; // <--------------------------- and add here
  public function myMethod()
  {
      $clients = $this->getTableLocator()->get('Clients');
  }
试试:


在App\Model\table上调用未知方法“getTableLocator”,我使用命令use-Cake\ORM\Locator\locatorawaretrit执行此错误;未知方法“getTableLocator”在App\Model\Table上调用,正如我前面所说,我使用了这个命令。你加载了trait吗?使用\Cake\ORM\Locator\locatorawaretrit?我在上面添加了更多的代码以使其更清晰,我不知道为什么它不起作用。我更新了在App\Model\table上调用的answerUnknown方法“getTableLocator”。我使用命令use Cake\ORM\Locator\locatorawaretrit来处理这个错误;未知方法“getTableLocator”在App\Model\Table上调用,正如我前面所说,我使用了这个命令。你加载了trait吗?使用\Cake\ORM\Locator\locatorawaretrit?我在上面添加了更多代码以使其更清晰,我不知道为什么它不起作用。我更新了我的答案