Q:

yii afterfind pass array to view

Inside my Model i have this code, this is partial code
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();
}

How do i pass array to view? When i do something like this, there was an error output by YII saying
htmlspecialchars() expects parameter 1 to be string, array given

A:

Yii afterfind() method is overrided to Postprocess AR attributes.
From the docs:

This method is invoked after each record is instantiated by a find
  method. The default implementation raises the onAfterFind event. You
  may override this method to do postprocessing after each newly found
  record is instantiated. Make sure you call the parent implementation
  so that the event is raised properly.

So it usually works like:
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
}

I am not sure what are you trying to do? but may be you want to automate some task (populating some array) after each find !!
In that case you can define a public array in your model:
$public car_arr = array();
Then populate it in your afterFind() and it will be accessible in the View.

