How To Get One To Many Values From Ui

I have a one to many relationship and the problem is that how do I show that to user ?

For eg a user can have many alias and he should be able to create as many alias as he wants to. I am having problem in finding out how to make user input as many values as he wants and then add them to db.

Please help.

For the recommendation below, I assume you have a separate table that holds the aliases and links back to your user table.


[*]You can start by using a JS library like select2 ( and give users the ability to keep adding aliases (referred to as tags in select2).

[*]You can convert your model from CActiveRecord to ManyManyActiveRecord (class found at This will allow you to do things like link one user ID to an array of alias IDs in one $model->setRelationRecords() call.

[*]On form submit, use your controller action to call $model->setRelationRecords() before calling $model->save().


This is a fully fleshed out solution, but it should guide you in the right direction. Note that I’ve used something similar in a project of mine.

Hope it helps!