第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從 $Auth 中檢索關(guān)聯(lián)字段的 CakePHP 語(yǔ)法

從 $Auth 中檢索關(guān)聯(lián)字段的 CakePHP 語(yǔ)法

PHP
手掌心 2022-06-17 17:12:49
CakePHP 3.7。這是我的“用戶”表:<?phpnamespace App\Model\Table;use Cake\Datasource\EntityInterface;use Cake\ORM\Association\BelongsTo;use Cake\ORM\RulesChecker;use Cake\ORM\Table;use Cake\Validation\Validator;class UsersTable extends Table{    public function initialize(array $config)    {        parent::initialize($config);        $this->setTable('users');        $this->setDisplayField('id');        $this->setPrimaryKey('id');        $this->belongsTo('Customers', [            'foreignKey' => 'customer_id',            'joinType' => 'LEFT'        ]);    }    public function validationDefault(Validator $validator)    {        ...     }    public function buildRules(RulesChecker $rules)    {        $rules->add($rules->isUnique(['email']));        $rules->add($rules->existsIn(['customer_id'], 'Customers'));        return $rules;    }}和“客戶”表:<?phpnamespace App\Model\Table;use App\Model\Entity\Customer;use Cake\Datasource\EntityInterface;use Cake\ORM\Association\HasMany;use Cake\ORM\Table;use Cake\Validation\Validator;class CustomersTable extends Table{    public function initialize(array $config)    {        parent::initialize($config);        $this->setTable('customers');        $this->setDisplayField('company_name');        $this->setPrimaryKey('id');        $this->hasMany('Users', [            'foreignKey' => 'customer_id'        ]);    }    public function validationDefault(Validator $validator)    {        ...    }}好吧,現(xiàn)在我想通過(guò) 檢索控制器和模板中的關(guān)聯(lián)字段customer_id,例如:$this->Auth->user('customer_id')); // <--- WORKS$this->Auth->user('Customers.company_name')); // <--- ???我不明白必須使用什么語(yǔ)法通過(guò)外鍵 ( customer_id) “導(dǎo)航”才能讀取Customers表中的其他字段。當(dāng)然,我可以使用一種解決方法:檢索“customer_id”值(如上)為該 ID 創(chuàng)建一個(gè)關(guān)于“客戶”過(guò)濾的查詢閱讀其他領(lǐng)域但我想這不是最好的方法。
查看完整描述

1 回答

?
墨色風(fēng)雨

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊

您需要自定義 Auth finder 查詢以包含客戶記錄。

但請(qǐng)注意,整個(gè) Auth 組件已被棄用,并將在版本 4 中替換為單獨(dú)的身份驗(yàn)證授權(quán)中間件插件。


查看完整回答
反對(duì) 回復(fù) 2022-06-17
  • 1 回答
  • 0 關(guān)注
  • 173 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)