Yii Framework Forum: Best Practice - external data files - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Best Practice - external data files

#1 User is offline   oorastard 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 22-March 10

Posted 25 March 2010 - 02:09 PM

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
0

#2 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 26 March 2010 - 08:21 AM

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.
0

#3 User is offline   oorastard 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 22-March 10

Posted 26 March 2010 - 12:39 PM

View PostDana, on 26 March 2010 - 08:21 AM, said:

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
0

#4 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 04 April 2010 - 01:42 PM

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....ute-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.
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users