Yii Framework Forum: Adding new columns to model - Yii Framework Forum

Jump to content

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

Adding new columns to model Rate Topic: -----

#1 User is offline   Bman900 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 27-March 11

Posted 11 November 2011 - 11:57 AM

Is there anything that I need to add to my model files when I create a new column in my database because if I just add it in the database and try to access it in yii, it never works. Basically I can never save to that field but yet if I recreate the model than I can save.

Thank you
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,710
  • Joined: 10-October 10
  • Location:Denmark

Posted 11 November 2011 - 12:15 PM

Look at the code in your corresponding model class.
And it should become clearer what you need to do. :)
"Less noise - more signal"
0

#3 User is offline   Bman900 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 27-March 11

Posted 11 November 2011 - 12:23 PM

View Postjacmoe, on 11 November 2011 - 12:15 PM, said:

Look at the code in your corresponding model class.
And it should become clearer what you need to do. :)


But thats the thing, the field I added did not need rules, relations and did not need to be searchable. I added it to a form but when I went to save it didn't save anything. I then tried assigning a direct value to it and then saving and yet again, nothing went into the database. But if I recreate the model, then saving works for that field. What causes this?
0

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,710
  • Joined: 10-October 10
  • Location:Denmark

Posted 11 November 2011 - 01:17 PM

If you don't want or need any validation rules, just add it to the array of safe attributes. :)
"Less noise - more signal"
0

#5 User is offline   auzadventure 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 20-August 15
  • Location:Singapore

Posted 15 March 2017 - 11:19 PM

Hi Everyone,

I just want to contribute this which took me 8 hours yesterday to figure out.
if you are getting
model.attribute undefine.


You need 3 things. That mean that the schema cache is not reflecting your new column

1. Add a validation rule in rules
2. Add label (for commenting)
3. Clear the cache!!! Yii:: app () ->cache->flush()
Questions are the Answer.

Wesvault - Premium Economy Software
Yii2 Framework Specialist
http://www.wesvault.com

Singapore
0

#6 User is offline   reykel 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 21-June 15
  • Location:Camaguey, Cuba

Posted 07 April 2017 - 07:28 PM

It should work, try cleaning up cache as auzadventure told you....
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