Hi there,
I am building a CMS with Yii. I am trying to build an "Article" model which should be highly customizable. In order to achieve that, I made an "Article" model belonging to a "Category" model. Category can be a blog post, a lengthy article, a portfolio item, a store product etc., definable by the administrator of the CMS. So the admin can add custom fields to each category, which appear to the editor and the end user.
This is my partial solution, with pros and cons:
Along with some fixed fields such as title and content in the Article model, I built two more related models: a CustomField model, belonging to Category (Category has many CustomField’s) and a CustomData model, belonging to CustomField (CustomField has many CustomData) and to Article (Article has many CustomData).
Each existing custom data unit can be identified in relation to the article id.
Each custom field in an article can be retrieved from the Category->CustomField relationship.
The CMS admin can specify name, data type, max length, etc. for each field.
The CustomData model has several fields for the different data types: value_bool, value_int, value_float, value_varchar, etc. Only one of them should be filled in, according to the data type defined in the related CustomField.
I have had my doubts on this approach, especially having to specify so many fields for the data unit. I am no MySQL guru but I think using a TEXT field to accommodate all data types would be more wasteful than having several specific fields.
Another solution I thought of was to get rid of the CustomData model and store all the custom data in a JSON string inside the Article model, but that would give me less structured data and might degrade search functionality.
I’m not looking for a plug-in. I am learning Yii and would like to implement this myself.
what are the Community’s thoughts on this? Has anybody else run into a similar case?
Thanks, and sorry for the lack of technical language. The source code is interwoven with other functionalities and I was afraid it might be confusing, but I can provide some if needed.
gm