php - Cake php 表连接两个字段
问题描述
我从使用 Cakephp 4.x 的 php 开始。
我烤了一张名为Persona
(西班牙语为人)的表,有两个字段,last_names
和names
.
我设置了setDisplayField
我的PersonaTable
tolast_names
但我想加入它names
,所以输出将是:
Doe, John
相关代码:
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('personas');
/*
* here I want to join last_names with names
*/
$this->setDisplayField('last_names');
$this->setPrimaryKey('id');
}
我的猜测是我必须在我的函数中创建一个PersonaTable
给出该结果的函数,但我不知道从哪里开始。
解决方案
将此功能添加到模型中
protected function _getFullName() {
return $this->first_name . ' ' . $this->last_name;
}
我可以full_name
作为一个字段访问,例如:
$persona->full_name
推荐阅读
- android - 启动时登录亚马逊崩溃
- python - 在 keras 中创建自定义的“不可微分”激活函数
- protobuf-net - Serializer.PrepareSerializer 和 RuntTimeTypeModel.CompileInPlace 有什么区别
- gnuplot - 如何设置彩盒的位置?
- python - 一个点在多边形内吗?方法有问题
- ssl - Nginx SSL 什么都不返回
- macos - 为什么创建新的 API 项目时出现兼容性错误?
- c# - 将失败的 IValueConverter 的 TextBox 状态绑定到 XAML 中的按钮
- azure - 复制前如何转换列?
- angular - 如何使用angular2中的primeng突出显示正在从列表中搜索的那些