【问题标题】:how display another object of data in a Templates如何在模板中显示另一个数据对象
【发布时间】:2019-05-10 06:21:21
【问题描述】:

这是Area类函数

        public function findLatestReport()
    {
        $getReport = Report::get()->filter('AreaID',$this->ID)
            ->sort('Date ASC')->first();
        return $getReport;
    }

这是报表类函数

    public function getWeatherStatus()
    {
        return $this->Fields()->filter('Name', 'Weather Status')->first();
    }

有什么方法可以显示 WeatherStatus 详细信息的“区域”模板。??

<% loop $findLatestReport %>
        {$WeatherStatus}
<% end_loop %>

【问题讨论】:

    标签: php silverstripe


    【解决方案1】:

    您需要使用with,而不是loop,因为您返回的是单个DataObject(使用-&gt;first())而不是列表。那你应该可以访问$WeatherStatus:

    <% with $findLatestReport %>
        {$WeatherStatus}
    <% end_with %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 2017-02-09
      • 2021-10-01
      • 2019-12-11
      • 2023-03-10
      相关资源
      最近更新 更多