You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在TYPO3中如何获取ObjectStorage内实体的protected title值

获取数组中的'title'值

根据你提供的数组结构,有两个不同层级的title值,获取方式分别如下:

1. 顶层数组的'title'值

顶层数组里的title是直接的键值对,假设你的数组变量名为$project,直接通过数组索引就能拿到:

$topTitle = $project['title'];
// 结果会是 'Ankoe'

2. services嵌套对象中的protected 'title'值

services是TYPO3 Extbase的ObjectStorage对象,里面存的是Services实体类的实例,它的title是protected属性,不能直接访问,必须用类里的getter方法(Extbase实体默认会生成getTitle()方法):

首先遍历ObjectStorage取出每个Services对象,再调用getter:

foreach ($project['services'] as $service) {
    $serviceTitle = $service->getTitle();
    // 结果会是 'Websites'
}

注意:如果你的Services实体没有自动生成getter方法,需要自己在模型类里添加:

class Services {
    // ... 其他代码
    public function getTitle() {
        return $this->title;
    }
}

内容的提问来源于stack exchange,提问作者Dev_fan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 12:25:39