Php 要查看的yii afterfind传递数组

Php 要查看的yii afterfind传递数组,php,yii,Php,Yii,在我的模型中,我有这个代码,这是部分代码 protected function afterFind () { $car= Car::model()->findAll("car_id = '{$this->model_id}'"); foreach($car as $cars) { $val['car_name'][] = $cars->car_name; $val['car_value'][] = $cars->car_va

在我的模型中,我有这个代码,这是部分代码

protected function afterFind ()
{
    $car= Car::model()->findAll("car_id = '{$this->model_id}'");
    foreach($car as $cars) {
        $val['car_name'][] = $cars->car_name;
        $val['car_value'][] = $cars->car_value;
    }
    $this->car_arr = $val;

    parent::afterFind();
}
如何将数组传递给视图?当我这样做的时候,YII输出了一个错误
htmlspecialchars()要求参数1为字符串,给定的数组

Yii
afterfind()
方法被重写为后处理AR属性

该方法在每个记录被find实例化后调用 方法。默认实现引发onAfterFind事件。你 可以重写此方法,以便在每次新发现后进行后处理 记录被实例化。确保调用父实现 以便正确地引发事件

所以它通常是这样工作的:

protected function afterFind()
{

  $this->attribute_a = customize($this->attribute_a); //return customized attribute_a
  $this->attribute_b = customize($this->attribute_b); //return customized attribute_b
  ....
  parent::afterFind(); //To raise the event
}
我不知道你想做什么?但是,您可能希望在每次查找后自动执行某些任务(填充某些数组)

在这种情况下,您可以在模型中定义公共数组:

$public car_arr=array()


然后将其填充到
afterFind()
中,即可在视图中访问它。

此错误应发生在视图中。您能找到并告诉我们发生此错误的线路吗?