• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resuable models

#1
[eluser]Treeda[/eluser]
Hi all,

i've stumbled over a little problem and just eager to know how you would solve this issue.

i have a modelclass, lets call it BookComments. This model handles with a table which stores comments for books. Also this class is dervied from MyBaseModel.

then i found out that i need exactly the same for magazins. (please ignore that i could use the same table).

so i just found out that the CommentsBook and CommentsMagazin is exactly the same due to the same tablescheme and so. The only difference are 2 lines in the headers.
2 small constants defining the field_id of the parent record and the table itself.

you know a comment has to be assigned to an item id so lets say commentsBook has this easy fields (id, book_id, comment) and magazin would have (id, mag_id, comment).

I don't want to have an copy of this thing, so what about having only one model called Comments and giving the table name to the constructor? ops ok this is not possible in codeigniter...

So how would you solve that? i really want to reuse the code and keep it as a model?

also a possible way would be creating a CommentsBook and CommentsMagazin deriving from Comments, but then i stumbled into problems about including the files, it seems that i can't easily nest includes with codeigniter.

Many Thanks for your help and insights.
Andi


Messages In This Thread
Resuable models - by El Forum - 08-04-2009, 06:45 AM
Resuable models - by El Forum - 08-04-2009, 07:23 AM
Resuable models - by El Forum - 08-04-2009, 07:28 AM
Resuable models - by El Forum - 08-04-2009, 07:28 AM
Resuable models - by El Forum - 08-04-2009, 07:30 AM
Resuable models - by El Forum - 08-04-2009, 07:37 AM
Resuable models - by El Forum - 08-04-2009, 07:45 AM
Resuable models - by El Forum - 08-04-2009, 10:27 AM
Resuable models - by El Forum - 08-04-2009, 12:05 PM
Resuable models - by El Forum - 08-04-2009, 01:47 PM
Resuable models - by El Forum - 09-07-2009, 04:13 PM
Resuable models - by El Forum - 09-07-2009, 04:35 PM
Resuable models - by El Forum - 09-08-2009, 01:05 AM
Resuable models - by El Forum - 09-08-2009, 04:01 AM
Resuable models - by El Forum - 09-08-2009, 04:51 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.