TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-17-2009, 01:00 PM   #1 (permalink)
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 60
Thanks: 10
flyingbuddha is on a distinguished road
Default OOP: Best place to load data in

Hi all,

I'm trying to recreate my blog using OOP and having a problem working out how to solve the following problem..

I have an ArticleCollection class (extends Collection class) that stores Articles (singleton's -is that right?).

Currently Articles takes a single parameter (article_id) and loads the information from a database.

I want ArticleCollection to loop through all the records in my database and create a new Article instance, then store it in an array / object, so I can access them when I want.

This is where I'm getting troubled, I would need to connect to the DB in ArticleCollection (for all records) AND Article (for the individual record), this smell's like I'm duplicating code. How should I approach this?

I've not written any code yet, trying to get it clear in my head before I set out.

Cheers.
__________________
Pro. Geek
http://www.mikeholloway.co.uk
flyingbuddha is offline  
Reply With Quote
Old 01-17-2009, 01:17 PM   #2 (permalink)
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 60
Thanks: 10
flyingbuddha is on a distinguished road
Default

Ok, I've solved it myself, I'll post back soon with a code implementation so that other's with the same question can see how I went about it.
__________________
Pro. Geek
http://www.mikeholloway.co.uk
flyingbuddha is offline  
Reply With Quote
Old 11-09-2009, 12:18 PM   #3 (permalink)
The Wanderer
 
eStrategy's Avatar
 
Join Date: Aug 2009
Location: Torquay
Posts: 16
Thanks: 2
eStrategy is on a distinguished road
Default

I've had the same issue myself. I made a system which has a client model object and a clients object (the clients object contains all the client objects). The clients object gets a list of all the clients ID's then creates a new client model object for each ID.

I'd like to see your solution.
__________________
Search Marketing
Send a message via Skype™ to eStrategy
eStrategy is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Venerable methods and the applications they are commonly trusted in. Village Idiot Tips & Tricks 7 11-06-2008 07:36 AM
SQL Injection and mysql_real_escape_string Durux General 58 05-15-2008 12:41 AM
Load data into combobox Filipe Costa Javascript, AJAX, E4X 2 03-28-2008 03:14 AM
The act of sharing your data Wildhoney General 0 12-06-2007 03:31 PM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM


All times are GMT. The time now is 07:14 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design