Yii Framework Forum: Dynamically adding properties to a Form Model - Yii Framework Forum

Jump to content

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

Dynamically adding properties to a Form Model Rate Topic: -----

#1 User is offline   EugeneA 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 18-April 12

Posted 19 July 2012 - 10:56 PM

I'm working on a project which involves generating some forms dynamically. Can anyone recommend the best way to dynamically create a form model, without having to pre-define all of the fields in the class as public properties?

I haven't dug into the code of the form model yet, but I'm guessing I'll have to extend the class and do some hacking...

edit:

After some digging, I think I am going to end up doing the following:

1. Add a private array called "dynamicValues" for storing data for dynamic properties.
2. Add a "dynamicAttributeNames" property for storing the names of dynamic attributes.
3. Override the "__set" and "__get" magic methods to see if the property being set is dynamic and store/retrieve it from the right data structure.
0

#2 User is offline   yiqing95 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 608
  • Joined: 27-December 10
  • Location:china

Posted 19 July 2012 - 11:28 PM

same topic : dynamicModel

:lol:
0

#3 User is offline   EugeneA 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 18-April 12

Posted 19 July 2012 - 11:32 PM

Thanks... I posted my solution in that thread.
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