[英]in cakephp4 how to access a model within a model
如何在 cakephp4.2 的 model 中訪問另一個 model? 我不清楚有關此問題的文檔,然后我可以對此進行查詢嗎? 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.C9A535FDC870D25
嘗試:
<?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 trait https://www.phptutorial.net/php-tutorial/php-traits/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.