Yii Framework Forum: Model Attributes And Post Problem - Yii Framework Forum

Jump to content

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

Model Attributes And Post Problem Rate Topic: -----

#1 User is offline   drxy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 12-September 12

Posted 02 January 2013 - 04:01 AM

In my form

<div class="row">
		<?php echo $form->labelEx($model,'aktif'); ?>
		<?php echo $form->dropDownList($model, 'aktif', array(''=>'Seçiniz',0=>'Pasif', 1=>'Aktif'));?>
		<?php echo $form->error($model,'aktif'); ?>
	</div>



I am posting KurumsalSite Form but an attribute "aktif" which belongs to Kurumsalsite i can't assign to $model->attributes . When i assign to

if(isset($_POST['KurumsalSite']))
{
$model->attributes=$_POST['KurumsalSite'];
}


"$model->aktif" is always "1". But, when i use this assignment

$model->aktif = $_POST['KurumsalSite']['aktif']


it is working. In my database (database is mysql) aktif field is tinyint. I don't want to write extra code. What is the problem . ::)
0

#2 User is offline   Kollipara Rama Krishna 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 12-May 12

Posted 02 January 2013 - 05:32 AM

if "aktif" is model attribute again why you are assigning?
0

#3 User is offline   drxy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 12-September 12

Posted 02 January 2013 - 06:18 AM

View PostKollipara Rama Krishna, on 02 January 2013 - 05:32 AM, said:

if "aktif" is model attribute again why you are assigning?


For recording different 'aktif' variables(0 or 1) to mysql.

Aktif is not static data it is dynamica data which is 0 or 1 . If user selects aktif 0 from form it comes 0 but if i want to assign model->attributes to POST attributes, it is always 1. I don't understand this situation.
0

#4 User is offline   Reza m 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 07-March 12

Posted 02 January 2013 - 06:18 AM

check model rules
0

#5 User is offline   drxy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 12-September 12

Posted 02 January 2013 - 06:30 AM

My model.

return array(
array('genislik, yukseklik, metin, aktif', 'required'),
array('id, site_id, genislik, yukseklik, aktif', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, site_id, genislik, yukseklik, metin, aktif', 'safe', 'on'=>'search'),
);


Is it wrong ?
0

#6 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 02 January 2013 - 06:56 AM

Will you explain your problem a bit more comprehensively.As far as I can gather,You have an attribute named 'atkif' which is a tinyint and you need to save it in your model.

FIrst of all Use a checkbox which will be better than a dropdownlist.Secondly,if it is a model attribute then $model->attribute=$_POST['FormName'] should work.If not set separately, using $model->atkif=$_POST['FormName']['field name'].


View Postdrxy, on 02 January 2013 - 06:30 AM, said:

My model.

return array(
array('genislik, yukseklik, metin, aktif', 'required'),
array('id, site_id, genislik, yukseklik, aktif', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, site_id, genislik, yukseklik, metin, aktif', 'safe', 'on'=>'search'),
);


Is it wrong ?

0

#7 User is offline   drxy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 12-September 12

Posted 02 January 2013 - 07:09 AM

View PostYearningForYii, on 02 January 2013 - 06:56 AM, said:

Will you explain your problem a bit more comprehensively.As far as I can gather,You have an attribute named 'atkif' which is a tinyint and you need to save it in your model.

FIrst of all Use a checkbox which will be better than a dropdownlist.Secondly,if it is a model attribute then

$model->attribute=$_POST['FormName']
should work.

If not set separately, using

$model->atkif=$_POST['FormName']['field name']
.



Thank you for your kindly message, but i think i explained my problem compherensively in my previous posts . You say

$model->attribute=$_POST['FormName']

should work, but it is not working exactly for this situation. I have also solve my problem with

$model->atkif=$_POST['FormName']['field name']

but why

$model->attribute=$_POST['FormName']


isn't work i didn't understand.
1

#8 User is offline   softark 

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

Posted 02 January 2013 - 07:28 AM

Hi drxy,

Well, I see nothing wrong so far in your posted code.
Would you please post your code of the controller action as a whole?
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