2017-09-02 53 views
0

我在實體此定義:CakePHP的3.5 - 實體 - 虛擬現場沒有顯示

protected $_virtual = [ 'full_name' ]; 

protected function _getFullName() 
{ 
    return($this->_properties['firstname'] . ' ' . $this->_properties['lastname']); 
}  

但FULL_NAME領域不受任何查詢檢索(分頁程序或找到(「全部」))...當表被稱爲關聯表時。

主表是GenPersons。 在這種情況下,該字段顯示正確。 但隨後我讓

 $this->paginate = [ 'contain' => ['GenPersons'] ] 

從AerPilots控制器(AerPilots是一個模型);並試圖獲得該字段爲

 $aerPilot->gen_person->full_name; 

什麼都沒有顯示。

我忘了什麼嗎?

回答

0

我找到了。 問題出在模型上的關聯中。 GenPersons表屬於常規插件。 AerPilots表屬於Aeronautical插件。 當我烤AerPilots模型,它生成的驗證碼

$this->belongsTo('GenPersons', [ 
     'foreignKey' => 'gen_person_id', 
     'className' => '**Aeronautical**.GenPersons' 
    ]); 

而且它必須是:

$this->belongsTo('GenPersons', [ 
     'foreignKey' => 'gen_person_id', 
     'className' => '**General**.GenPersons' 
    ]);