CakePHP的3.5 - 实体 - 虚拟现场没有显示
问题描述:
我在实体此定义: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;
什么都没有显示。
我忘了什么吗?
答
我找到了。 问题出在模型上的关联中。 GenPersons表属于常规插件。 AerPilots表属于Aeronautical插件。 当我烤AerPilots模型,它生成的验证码
$this->belongsTo('GenPersons', [
'foreignKey' => 'gen_person_id',
'className' => '**Aeronautical**.GenPersons'
]);
而且它必须是:
$this->belongsTo('GenPersons', [
'foreignKey' => 'gen_person_id',
'className' => '**General**.GenPersons'
]);