Yii Framework Forum: mb_strlen() expects parameter 1 to be string, array given - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

mb_strlen() expects parameter 1 to be string, array given Rate Topic: -----

#1 User is offline   mithila 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 116
  • Joined: 18-April 11

Posted 11 May 2011 - 03:25 AM

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()
	{
		$connection=Yii::app()->db;
		$model=new BusType;
         $model2=new BusProducts;
		// Uncomment the following line if AJAX validation is needed
 $this->performAjaxValidation($model);


//Get the number of models you will be working with 
 $maxRows =count($_POST['quantity']);



		if(isset($_POST['BusType']))
		{
			$model->attributes=$_POST['BusType'];
				$model2->attributes=$_POST['BusProducts'];
			
			if($model->save())
				{
					$bus_type_id=$model->bus_type_id;
				
					 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)"; 
 
					  
			
$command=$connection->createCommand($sql);
$command->bindParam(":bus_type_id",$bus_type_id,PDO::PARAM_INT);
$command->bindParam(":quantity",$quantity,PDO::PARAM_INT);
$command->bindParam(":product_id",$product_id,PDO::PARAM_INT);
$command->bindParam(":cat_id",$cat_id,PDO::PARAM_INT);
$command->bindParam(":subcat_id",$subcat_id,PDO::PARAM_INT);

$command->execute();
		
							}
				$this->redirect(array('view','id'=>$model->bus_type_id));
		}
		}

		$this->render('create',array(
			'model'=>$model,
			'model2'=>$model2,
		));
	}




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

#2 User is offline   dmaus 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 22-November 10

Posted 11 May 2011 - 06:18 AM

View Postmithila, on 11 May 2011 - 03:25 AM, said:

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?
0

#3 User is offline   mithila 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 116
  • Joined: 18-April 11

Posted 11 May 2011 - 06:25 AM

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.


Thanks
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,045
  • Joined: 16-February 11
  • Location:Japan

Posted 16 May 2011 - 06:28 AM

Hi mithila,

Collecting Tabular Input might be what you want.
0

#5 User is offline   mithila 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 116
  • Joined: 18-April 11

Posted 16 May 2011 - 07:50 AM

Hey,


Thanks for the reply.will try that
0

#6 User is offline   riyazMuhammed 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 13-September 12
  • Location:Bangalore

Posted 28 December 2012 - 02:23 AM

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'),
                    array(
                        'empty'=>'',
                        '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 !!!!
0

#7 User is offline   uleen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 05-July 13

Posted 05 July 2013 - 01:56 AM

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);

0

#8 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,045
  • Joined: 16-February 11
  • Location:Japan

Posted 06 July 2013 - 10:28 PM

/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users