mb_strlen() expects parameter 1 to be string, array given

Hi all,

Can anybody take a look at my code and tell me as to why i’m getting an error?

The following is my code

public function actionCreate()



		$model=new BusType;

         $model2=new BusProducts;

		// Uncomment the following line if AJAX validation is needed


//Get the number of models you will be working with 

 $maxRows =count($_POST['quantity']);










					 for ($i = 0; $i < $maxRows ; $i++) 


			$quantity = $_POST['quantity'][$i];

			 $product_id = $_POST['product_id'][$i];

			  $cat_id = $_POST['cat_id'][$i];

			   $subcat_id = $_POST['subcat_id'][$i]; 

			$sql = "insert into bus_products (bus_type_id,quantity,product_id,cat_id,subcat_id) values (:bus_type_id,:quantity,:product_id,:cat_id,:subcat_id)"; 





















The error which i am getting is: mb_strlen() expects parameter 1 to be string, array given .

Questions is: Where does this error occur? Which file at which line?

Hi dmaus,

I have a field called quantity. This field is in a loop. i want to save all the values of quantity in the loop for which i need to convert the filed quantity to an array as follows

 <? echo $form->textField(BusType::model(),'quantity[]',array('size'=>10,'maxlength'=>255));


	?>   // as an array

If i put the code as follows the error goes.

 <? echo $form->textField(BusType::model(),'quantity',array('size'=>10,'maxlength'=>255));


	?> //not an array

But i need it be an array to update the db correctly.

How do i go about this. Suggest if there is any other way of doing it.


Hi mithila,

Collecting Tabular Input might be what you want.


Thanks for the reply.will try that

Hey I have dropDownList with ‘multiple’=>‘multiple’, So $_POST[‘mymodel’][‘attribute’][] is an array by default!!!

And following is my dropdownlist code :

  <?php echo $form->labelEx($questionTag,'TagName'); ?>

                    <?php echo $form->dropDownList($questionTag,'TagName', 

                    CHtml::listData(Questiontag::model()->findAllByAttributes(array('OwnerID'=>Yii::app()->user->id)), 'TagID', 'TagName'),



                        'multiple'=>'multiple','style'=>'width:181px; height:98px; margin-right:10px;','size'=>'5','id'=>'TagsList',

                        'options' => $parsedSelectedTags));


SO as we can see I haven’t explicitly defined TagName as TagName[] but still I get the same error mb_String expecting string.

Whats wrong ?

PS : when i remove ‘multiple’=>‘multiple’ validation runs perfect !!!

But I want multiple dropdownlist itself !!!!

My decision for this problem:

In model make method beforeValidate()

and doing something like this into this method

$this->select_value = implode(" ",$this->select_value);

[color="#006400"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]