I’m currently in the planning part of my newest website, and i’m planning to use checkboxes. The point of the website is it will offer some data on books.
When creating a book on the website, the user will have to select which genres the book is (it is possible to select multiple genres) through checkboxes.
The problem however is, i’m unsure of how this should be made both on server- and client-side.
My initial thoughts:
The database will contain a column for each possible genres (boolean values)
If the user checks the checkbox, the value will be set to 1, else it will be set to 0
In the view page, if the value of the genre is 1, the name of the genre will be displayed, else it will not.
Is this the right method to use, and if so, how do i create the last point? I mean, what should i place in the view, the controller and the model-file (i’ve not understood MCV fully yet, but i’m learning by trying )?
It is possible to do it as you are planning to, but for a good design (keyword: normalisation of a database) use three tables - one with your books, one with all possible genres and one with the bookid’s and the genreid’s. It is a little more difficult in the beginning (also the yii part) but will save you trouble in the end!
I’ve looked at the tagging extension, and i think I’m gonna stick with the method klammeraffe suggested. That way it’s possible to look up all books with a certain genre, without the chance of missing some because of misspelling or another word of the same genre.