Reputation: 64
I'm trying to create a blog system using YII. Examples and Tutorials are available. But they use a multi-value table for a Post. Its something like
Post(Id, Title, Content, Author, Tags)
Here there are multiple values (separated by comas) in Tags column. So I created a schema to avoid this and now I have tables like this,
Post(Id, Title, Content, Author) Tag(Id, Name)
PostHaveTags(Post_Id, Tag_Id)
after normalizing the schema.
I could manage to make a relation in relations() method. But I cannot figure out how to get inputs from a view and validate values of 'tags'. Can anyone help me regarding this please?
Thanx.
Upvotes: 0
Views: 373
Reputation: 64
Finally I found the solution. And here is what I did,
First I got the appropriate data from the view and validated them, defining some rules. Then in the afterSave() method I inserted the gathered data into relative relations manually. I don't know whether there is an easy way. But I think, if so, YII will generate the code for us. :)
Thanx guys for helping.
Upvotes: 0
Reputation: 1125
You can try to use javascript to allow your forms to grow dynamically and include zero, one or many tags. which you can validate in the model using custom validation rules.
Upvotes: 1