Yii Framework Forum: Use Of Jmultiselect2Side Widget In Yii - Yii Framework Forum

Jump to content

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

Use Of Jmultiselect2Side Widget In Yii Using jmultiselect2side widget ,save the selected data into database Rate Topic: -----

#1 User is offline   SrikanthMaggidi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-May 14
  • Location:Hyderabad,India

Posted 19 May 2014 - 02:59 AM

Download yii jmultiselect2side widget
http://www.yiiframew...ltiselect2side/


Please follow the steps to create multiple selection of values and get selected values store into database.

at view::
<? $cities=array("Fremont"=>"Fremont","Heyward"=>"Heyward","Oalankd"=>"Oalankd","SanJose"=>"SanJose","SantaClara"=>"SantaClara","Sunny Vale"=>"Sunny Vale");?>
<?php  $this->widget('application.extensions.jmultiselect2side.Jmultiselect2side',array(
					'model'=>$citymodel,
					'attribute'=>'city_name', //selected items
					'labelsx'=>'Available',
					'labeldx'=>'Selected',
					'moveOptions'=>false,
					'autoSort'=>'true',
					'search' =>'Seach:',
					//'list'=>CHtml::listData($codes,'city_name','city_name'), // or use any model to get values from database eg: <?php $codes = City::model()->findAll();?>
					'list'=>$cities,
					));	?>


In Controller to get selected values and save into to database::

	public function actionCities($id)
	{
			$criteria = new CDbCriteria;
       		$criteria->condition = 't.region_id=:regionid';
       		$criteria->params = array(':regionid'=>$id);
        	$exists = RegionCities::model()->exists($criteria);
        	if (!$exists)
			{
			$citymodel=new RegionCities;
			$citymodel->region_id=$id;
			}
			else
			{
			$citymodel=RegionCities::model()->findByAttributes(array('region_id'=>$id));	
			$citymodel->region_id=$id;
			}
		
			if(isset($_POST['RegionCities'])&&!isset($_POST['cancel']))
			{
				$citymodel->attributes=$_POST['RegionCities'];
				$citymodel->region_id=$id;
				if(isset($_POST['RegionCities']['city_name']))
				{
				if($_POST['RegionCities']['city_name']!=NULL&&$_POST['RegionCities']['city_name']!=0)
					$citymodel->city_name=implode(";",$_POST['RegionCities']['city_name']);
				}	
				else	
				{
				$citymodel->city_name=NULL;
				}
				if($citymodel->save())
				{
				Yii::app()->user->setFlash('success', "Update successfully");
				$this->redirect(array('admin'));
				}
			}
			if (isset($_POST['cancel'])) 
			{
				$this->redirect(array('admin'));
			}
			if(isset($citymodel->city_name))
			$citymodel->city_name=explode(';',$citymodel->city_name);
			$this->render('cities',array('citymodel'=>$citymodel));
	}




Please post for any queries in jmultiselect2side widget.

Thanks,
Srikanth
0

#2 User is offline   Ramdhani 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 17-March 14

Posted 21 July 2014 - 09:18 PM

View PostSrikanthMaggidi, on 19 May 2014 - 02:59 AM, said:

Download yii jmultiselect2side widget
http://www.yiiframew...ltiselect2side/


Please follow the steps to create multiple selection of values and get selected values store into database.

at view::
<? $cities=array("Fremont"=>"Fremont","Heyward"=>"Heyward","Oalankd"=>"Oalankd","SanJose"=>"SanJose","SantaClara"=>"SantaClara","Sunny Vale"=>"Sunny Vale");?>
<?php  $this->widget('application.extensions.jmultiselect2side.Jmultiselect2side',array(
					'model'=>$citymodel,
					'attribute'=>'city_name', //selected items
					'labelsx'=>'Available',
					'labeldx'=>'Selected',
					'moveOptions'=>false,
					'autoSort'=>'true',
					'search' =>'Seach:',
					//'list'=>CHtml::listData($codes,'city_name','city_name'), // or use any model to get values from database eg: <?php $codes = City::model()->findAll();?>
					'list'=>$cities,
					));	?>


In Controller to get selected values and save into to database::

	public function actionCities($id)
	{
			$criteria = new CDbCriteria;
       		$criteria->condition = 't.region_id=:regionid';
       		$criteria->params = array(':regionid'=>$id);
        	$exists = RegionCities::model()->exists($criteria);
        	if (!$exists)
			{
			$citymodel=new RegionCities;
			$citymodel->region_id=$id;
			}
			else
			{
			$citymodel=RegionCities::model()->findByAttributes(array('region_id'=>$id));	
			$citymodel->region_id=$id;
			}
		
			if(isset($_POST['RegionCities'])&&!isset($_POST['cancel']))
			{
				$citymodel->attributes=$_POST['RegionCities'];
				$citymodel->region_id=$id;
				if(isset($_POST['RegionCities']['city_name']))
				{
				if($_POST['RegionCities']['city_name']!=NULL&&$_POST['RegionCities']['city_name']!=0)
					$citymodel->city_name=implode(";",$_POST['RegionCities']['city_name']);
				}	
				else	
				{
				$citymodel->city_name=NULL;
				}
				if($citymodel->save())
				{
				Yii::app()->user->setFlash('success', "Update successfully");
				$this->redirect(array('admin'));
				}
			}
			if (isset($_POST['cancel'])) 
			{
				$this->redirect(array('admin'));
			}
			if(isset($citymodel->city_name))
			$citymodel->city_name=explode(';',$citymodel->city_name);
			$this->render('cities',array('citymodel'=>$citymodel));
	}




Please post for any queries in jmultiselect2side widget.

Thanks,
Srikanth



how to create multiple into database? please.
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