Yii Framework Forum: data from Dropdownlist not inserting into database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

data from Dropdownlist not inserting into database Rate Topic: -----

#1 User is offline   jeewendrakumar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 21-October 10

Posted 02 November 2010 - 08:12 AM

i have two mdoel 1)Issue
2)Category

and in the issue view page, i am able to get the data into Dropdownlist form tbl_category database


<div>
<?php echo $form->labelEx($model, 'category'); ?>
<?php echo CHtml::activeDropDownList($model, 'category_id',Category::model()->getCategoryOptions()); ?>
<?php echo $form->error($model, 'category'); ?>
</div>
but the data is not inserting into tbl_issue database

plz reply

thanks in advance
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 02 November 2010 - 08:49 AM

Your function getCategoryOptions() should return an array like that:

array('primaryKey'=>'displayData')


You can create it with CListData:

<?php echo CHtml::activeDropDownList($model,'category_id',
			CHtml::listData(Category::model()->findAll(),
			'primaryKey','optionName'));



You can check if $_POST['modelId']['category_id'] is corrected, if it is so it means that the attribute category_id is not safe, you have to add to the list of safe attributes.
1

#3 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,448
  • Joined: 04-October 10

Posted 02 November 2010 - 09:03 AM

Adding a bit more explanation to the correct answer of Zac, I would say that in your Controllers Action you receive the post also like:

$model->attributes = $_POST['modelID'];

$model->save();

---
if it doesnt save do in your rules():

array('category_id','safe'),

---

best
┬┐How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
1

#4 User is offline   jeewendrakumar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 21-October 10

Posted 03 November 2010 - 12:27 AM

View Postzaccaria, on 02 November 2010 - 08:49 AM, said:

Your function getCategoryOptions() should return an array like that:

array('primaryKey'=>'displayData')


You can create it with CListData:

<?php echo CHtml::activeDropDownList($model,'category_id',
			CHtml::listData(Category::model()->findAll(),
			'primaryKey','optionName'));



You can check if $_POST['modelId']['category_id'] is corrected, if it is so it means that the attribute category_id is not safe, you have to add to the list of safe attributes.



its working
thanks for suggestion
0

#5 User is offline   jeewendrakumar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 21-October 10

Posted 03 November 2010 - 12:27 AM

View PostAntonio Ramirez, on 02 November 2010 - 09:03 AM, said:

Adding a bit more explanation to the correct answer of Zac, I would say that in your Controllers Action you receive the post also like:

$model->attributes = $_POST['modelID'];

$model->save();

---
if it doesnt save do in your rules():

array('category_id','safe'),

---

best


its working fine
thanks for suggestion
0

#6 User is offline   richdad.tx 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 20-October 11

Posted 03 January 2012 - 08:55 AM

i have two model
1)Tree
2)TreeType

_form.php(tree.php)

echo CHtml::activeDropDownList($model,'id_typetree',$model->getTypeTree());


Tree.php

 public function getTypeTree()
    {
        $TypeArray = CHtml::listData(Treetype::model()->findAll(array('order' => 'name')), 'id_typetree', 'name');
       
        return $TypeArray;
        
    }


the data is not inserting into tbl_tree database. ??????

helf me...!
thanks for reply
0

#7 User is offline   richdad.tx 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 20-October 11

Posted 06 January 2012 - 07:02 AM

View Postrichdad.tx, on 03 January 2012 - 08:55 AM, said:

i have two model
1)Tree
2)TreeType

_form.php(tree.php)

echo CHtml::activeDropDownList($model,'id_typetree',$model->getTypeTree());


Tree.php

 public function getTypeTree()
    {
        $TypeArray = CHtml::listData(Treetype::model()->findAll(array('order' => 'name')), 'id_typetree', 'name');
       
        return $TypeArray;
        
    }


the data is not inserting into tbl_tree database. ??????

helf me...!
thanks for reply



hi. ok.

thanks all
0

#8 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 January 2012 - 07:07 AM

Er, Richdad.tx - does this mean you've got it solved? :)



"Less noise - more signal"
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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