Yii Framework Forum: Creating A Drop Down List - Yii Framework Forum

Jump to content

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

Creating A Drop Down List

#1 User is offline   vaijanath 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 09-October 13

Posted 29 October 2013 - 05:43 AM

Hello, I have developed a web application using yii framework. Now i want to add drop down list into my app. This drop down should contain data from another table called "Forms" which is in the same database named "manthan" as using which i have created my app, based on the item in the list i select in drop down list, it should display the data which is in the current table named "Report". How can i relate these two tables in order to achieve above mentioned task? and how can i add a drop down list in my current app. Can somebody please tell me? It will be very helpfull if your responses are in step by step.
0

#2 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 29 October 2013 - 10:20 AM

if you use form so you have
echo $form->dropDownList($model,'form_id',Forms::model()->findAll());

or, if you do not use it:
echo CHtml::dropDownList('form_id',Forms::model()->findAll());

http://www.yiiframew...DownList-detail
http://www.yiiframew...DownList-detail
www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#3 User is offline   vaijanath 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 09-October 13

Posted 30 October 2013 - 06:06 AM

View PostShahcheraghean, on 29 October 2013 - 10:20 AM, said:

if you use form so you have
echo $form->dropDownList($model,'form_id',Forms::model()->findAll());

or, if you do not use it:
echo CHtml::dropDownList('form_id',Forms::model()->findAll());

http://www.yiiframew...DownList-detail
http://www.yiiframew...DownList-detail


Hi, i have added a drop down list in my page. it should display data on which item in the list is selected. it contains data of a column field named "FormName".
Here is my model code:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
if(!empty($this->RequestedForm))
{
$criteria->condition = "FormName = $this->RequestedForm";
}
$criteria->compare('FormName',$this->FormName,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>false,
));
}
Here is my controller code:
public function actionSearch()
{
$model=new Report('search'); // your model
$model->unsetAttributes(); // clear any default values
if(!empty($_POST))
{
$model->RequestedForm = $_POST['RequestedForm'];
}
//echo "<script>".$model->RequestedForm.";</script>";
if(isset($_GET['Report']))
$model->attributes=$_GET['Report'];
$this->render('admin',array(
'model'=>$model,
));
}
Here is my admin.php in view:
<?php $list=CHtml::listData(Report::model()->findAll(), 'Id', 'FormName');
echo 'select a form';
echo CHtml::dropDownList('RequestedForm', $model->FormName, $list, array('empty' => '(Select a state)','onChange' => 'submit','submit' => array('report/search')));?>

but its not displaying accoding to the selected FormName in the drop down list. Can u tell me what am i missing?
0

#4 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 01 November 2013 - 10:08 AM

Maybe you need it:
echo CHtml::activeDropDownList($model,'RequestedForm',Report::model()->findAll(), array('empty' => '(Select a state)','onChange' => 'submit','submit' => array('report/search')));

;)
www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
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