Best Practice - external data files

Greetings,

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:




question_arr {

    [0]='question 1'

    [0]='question 2'

    [0]='question 3'

    [0]='question 4'

    [0]='question 5'

}



I see a couple options for accessing this data or other file data:

  • create a model for accessing the file

  • create a function within the current model that will return the array

I’m am not sure which route is better or if I am overlooking another solution.

Any suggestions/comments would be appreciated,

Oorastard

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.

Hope that helps.

That does help.

Thank you

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.