Model validation

Hi,

I have one model name Agency_bill_book

and controller AController

I am saving all details on one click my action for create is below…


public function actionCreate(){

        $model = new AgencyBillBook();  

        $model->scenario = AgencyBillBook::SCENARIO_CREATE;

        $request=Yii::$app->request;

        // i am taking only month and sundays from post, rest things from database

        $dates=$request->post('date1');//for month

        $dd=$request->post('date');//for dates date is an array

        $prices=$request->post('price');//price is also an array

        //print_r($dates);exit;

        

        $alldate=Yii::$app->mycomponent->calsunday();//this will calculate all sundays in selected month

      

        

        foreach ($alldate as $date){

            $agency=$model->get_all_agencies($date);//this will get all agencies on particulat date

               

            $i=1;

                foreach ($agency as $key=> $val) {

                   ;

                    $model->id=NULL;

                    $model->isNewRecord = TRUE; 

                    $model->agency_id=$val['agency_id'];

                    $model->issue_date=$date;

                    $model->total_price=$price;

                    $dsc=$model->get_discount($tot);

                    $per=($price*$dsc)/100;

                    $model->discount=$dsc;

                    $discounted=$price-$per;

                    $model->discounted_amt=$per;

                    $model->final_total=$discounted;

                    $model->created_on=  date('Y-m-d H:i:s');

                   if($model->validate() && $model->save()){

                    continue;

                   }else{

                       return $this->render('welcome',['error'=>$model->errors]);

                   }

                    

                    

        }

        $this->actionShow($dd);

        

    }

    }

And my scenario for is this


 public function scenarios()

{

    $scenarios = parent::scenarios();

    $scenarios[self::SCENARIO_CREATE] = [[['issue_date'],'unique'], [['issue_date'], 'string', 'max' => 32],];


    return $scenarios;

}

     this is not working for me...


     I am getting this error 

 PHP Notice – yii\base\ErrorException

Array to string conversion





    1. in /var/www/html/advanced/vendor/yiisoft/yii2/validators/Validator.php at line 234


         * @param \yii\base\Model $model the data model being validated

         * @param array|null $attributes the list of attributes to be validated.

         * Note that if an attribute is not associated with the validator,

         * it will be ignored.

         * If this parameter is null, every attribute listed in [[attributes]] will be validated.

         */

        public function validateAttributes($model, $attributes = null)

        {

            if (is_array($attributes)) {

                $attributes = array_intersect($this->attributes, $attributes);

            } else {

                $attributes = $this->attributes;

            }

            foreach ($attributes as $attribute) {

                $skip = $this->skipOnError && $model->hasErrors($attribute)

                    || $this->skipOnEmpty && $this->isEmpty($model->$attribute);

                if (!$skip) {

                    if ($this->when === null || call_user_func($this->when, $model, $attribute)) {

                        $this->validateAttribute($model, $attribute);




Please help me…or suggest me better way to do this…