Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2008, 07:18 PM
Junior Member
 
Join Date: May 2008
Posts: 2
Default How to access an "abstraction" of a table ?

Hello everybody,

The example below should demonstrate quite clearly my issue.

Assuming that I have in my DB the following table :

Code:
CREATE TABLE `users` (
    `userid` INT NOT NULL,
    `username` VARCHAR( 50 ) NOT NULL,
    `avatar1` INT, -- ID of the 1st avatar picture or NULL
    `avatar2` INT, -- ID of the 2nd avatar picture or NULL
    `avatar3` INT -- ... (3 pictures max allowed)
) ;
(I know, this is not how it should be, but sometimes, reality isn't.)

So I'd like to access my avatar data as an array :

PHP Code:
<?php
// After getting a row
if (count($myRow->avatar) > 0)
    
$this->view->avatar = new Avatar($myRow->avatar[0]) ;
This is just an example. The abstraction I'd like to create should be far more complicated. The point is : how does one create, access et write trough some abstraction of the real DB ? What are the good practices ? Where am I supposed to write the logic that stands between Model and Controller ?

I already found those two tutorials, and they seem quite interesting.

I'm looking forward to any other suggestions !

Regards
elvex
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-11-2008, 07:59 PM
Junior Member
 
Join Date: Mar 2008
Posts: 26
Default

Sorry, but I don't clearly understand your questions, however you should read something about OOP (object oriented programming :P), ORM and programming patterns, like Active Record or Table Data Gateway, Row Data Gateway, DAO (Data Access Object), etc.

Also read some on offical ZF's manual about Zend_Db (as I remember it's build upon a clear example of bug tracking application)

Quote:
Where am I supposed to write the logic that stands between Model and Controller ?
Model represents data from the databse. In controller you should initialize model and access its methods to get data (which model previously queried and formed into desired form - eg. Menu::getMenu() will return array containing menu items).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-11-2008, 08:46 PM
Junior Member
 
Join Date: May 2008
Posts: 2
Default

Well, I sure have to read a lot...

Quote:
Originally Posted by kuba View Post
which model previously queried and formed into desired form - eg. Menu::getMenu() will return array containing menu items).
If the Table object is an exact replication of the SQL Table, where is the model "formed into desired form" ?
Is the array returned by Menu::getMenu() stored somewhere when the row is instancied, or is it created just on demand (when the method is called) ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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



All times are GMT. The time now is 11:54 AM.