Recent Posts

Wednesday, June 29, 2011

CakePHP: Auto populating foreign key dropdown fields

I wasted so much time figuring out to populate the drop down from foreign classes in cake PHP and wished it would be best if someone could have written from beginning to end to help the beginners of Cake like me.

Finally i figured it out and you guys can benefit from it.

I have two tables articles and users, user write articles so there is one to many relationship. I need user drop down in articles forms to say who is this user writing the article.

User table has
id
Name

Article table has
id
Title
user_id

So my Article Model will look like below:


My user model will look like below:


My Article Controller will look like below


The Add view will look like below:


Similarly Edit View will look like below


Hope this will help kick start your Cake Php learning ... enjoy coding

Related Posts by Categories




4 comments:

sunny gulati said...

Thank u sooo much.. finding this solution from last 24 hours.. finally got it. works like a magic.. :-)

nikkylooka said...

You saved my life. Thanks :3

Iheb Saad said...

Thank you very much
That was very helpful even after many years !

Adams Kevin said...

I ADAMS KEVIN, a representative Aiico Insurance plc, we trust and respect for individual differences in day out a loan. We will provide 2% of the loan's interest rate. If you are interested in this business contact us by e-mail: (adams.credi@gmail.com) now transfer their loan documents issued properly. Do you need a loan to set up business or school if you are very welcome to Aiico Insurance plc. You can also contact us by e-mail: (adams.credi@gmail.com). We first week can request a balance transfer.

DO YOU NEED LOAN FOR PERSONAL BUSINESS? IF YOU CONTACT YOUR EMAIL ABOVE TO PROCEED WITH YOUR LOAN TRANSFER IMMEDIATELY OK.

Post a Comment