I have a text file of questions that we are using for user verification. My old (non-Yii) code uses the file() function to put the contents in an array. So I end up with something like:
I’m hardly expert, but I would think that the best practice would be to make a model for the questions.
If you do that then you can give yourself the ability to easily administrate those basic questions as well should the need arise, and if the file structure needs to change at any point, you’re already abstracted from it.
Well I actually would move those files to tables in a database, and create some nice UI for administration of those questions, then a simple couple models of this tables and you are all done with a nice system. you can take a look into EAV patter to see who can this be done: http://en.wikipedia.org/wiki/Entity-attribute-value_model
On the other hand if you dont have the time and/or can do it as per client requirements ,internal politics, time or whatever reasion, then pyeah creating a model for accesing contents in the file would be ideal as you can take advantage of the model utilities like validation in this case create a class that extends from CModel perhaps a CFileModel which would hold the name of the file to be parsed, and then several other models inherit from this class with custom file name in case you need to parse more than 1 file.