在用find获取数据后,我们要对所获取到的数据做一些处理,这时,直接在模型层覆盖cakephp内置的回调函数,使用find时会自动调用。
其中$baomings 就是find 到的 $this->data
public function afterFind($baomings) { foreach ($baomings as $key => $val) { $baomings[$key][‘Baoming‘][‘status_cn‘] = "未知"; if ($val[‘Baoming‘][‘invalid‘] == 1) { $baomings[$key][‘Baoming‘][‘status_cn‘] = "无效"; } else { if ($val[‘Baoming‘][‘status_trace‘] == 0) $baomings[$key][‘Baoming‘][‘status_cn‘] = "未开始"; else if ($val[‘Baoming‘][‘status_trace‘] >= 1 && $val[‘Baoming‘][‘status_trace‘] < 6) { $baomings[$key][‘Baoming‘][‘status_cn‘] = "正在跟踪"; } else if ($val[‘Baoming‘][‘status_trace‘] == 6) { $baomings[$key][‘Baoming‘][‘status_cn‘] = "已经签约"; } else if ($val[‘Baoming‘][‘status_trace‘] == 7 || $val[‘Baoming‘][‘status‘] == 3) { $baomings[$key][‘Baoming‘][‘status_cn‘] = "已竣工"; } } } return $baomings; }
时间: 2024-11-04 11:10:30