Yii Framework Forum: How To Access Form Element In Controller - Yii Framework Forum

Jump to content

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

How To Access Form Element In Controller Rate Topic: -----

#1 User is offline   Ashish Tyagi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 13-December 12

Posted 16 January 2013 - 09:21 PM

How can I access the elements of my view in controller. lets I have a field name 'type' in my form field and I want to access the value of that field in my controller class. How can I achieve that. I saw where we are fetching all attributes

$model->attributes=$_POST['Alerts'];
How can I get a specific attribute from $model->attributes Thanks in advance

I want to pass a value from form to the model.
Thanks
Ashish Tyagi
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 578
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 16 January 2013 - 11:11 PM

Getting One value from the form
$alerts=$_POST['Alerts'];
echo $alerts['property'];

// setting one value to model
$model->setAttributes(array(
'property'=>'value'
));

Further reading
http://www.yiiframew...tributes-detail
thanks
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   Shobhith C 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 10-January 13
  • Location:Cochin

Posted 17 January 2013 - 01:28 AM

hi
you can access it directly by
$var=$_POST['Alerts']['type']; 

or
$model->attributes=$_POST['Alerts']; 
$var=$model->type;

attribute `type` must be defined in model class or it must be part of table related to model class
1

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