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

in cakephp4 how to access a model within a model

如何在 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');

https://api.cakephp.org/4.0/class-Cake.ORM.TableRegistry.html

尝试:

<?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');
  }

并阅读https://book.cakephp.org/4/en/orm/table-objects.html#using-the-tablelocator

并学习如何使用 php 特征 https://www.phptutorial.net/php-tutorial/php-traits/