Jump to content

collection classes help


action

Recommended Posts

There is a brief introduction on:

http://www.nomadhacker.com/uncategorized/creating-a-php-collection-class/comment-page-1/#comment-1319

 

i need to create a collection class with students,(add/delete,etc) but it must be using the "collection class" concept.

 

It looks like you found it.  What's the problem?

You'll probably want your collection implement Iterator and Countable.

(http://us3.php.net/Countable)

(http://us3.php.net/manual/en/class.iterator.php)

 

However, there's more than one way to skin a cat. There's all sorts of different types of collections you could implement: stacks, queues, linked lists, trees, etc.. I use collections on my blog, here's an example:

 

The abstract class, which implements Iterator and Countable:

http://github.com/rkeplin/Blog/blob/master/library/Keplin/Model/Collection/Abstract.php

 

A class which extends the above class:

http://github.com/rkeplin/Blog/blob/master/application/models/CategoryCollection.php

 

The class which acts as items in the above collection:

http://github.com/rkeplin/Blog/blob/master/application/models/Category.php

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.