Jump to content

Opinions - mvc


glenelkins

Recommended Posts

say i have a model called messageModel wich will have to begin with 2 functions "getInbox ( $userID)" and "getSent ( $userID )"  - i think its quite clear what they are meant to do.

 

So lets say we call the model function $_messageModel->getInbox ( 1 ) will get the inbox of user id of 1, and return an array of the database table like this $messageArray[MESSAGE_ID_HERE] = array ( message variables here - subject - content etc )

 

Now, in the message table there is a "receivedfromuserid" field. I have another model that gathers a users information.

 

What are peoples opinions on the best way to link the 2 models so the message sender can be linked to the "receievedfromuserid" ?? Call the user model from the message model? Parse a copy of the user model to the message model?

 

 

Link to comment
https://forums.phpfreaks.com/topic/169391-opinions-mvc/
Share on other sites

Not sure what that has to do with the MVC pattern....

 

 

 

But anyway, one option would be to have a Message object with attributes from the table and have access methods.

 

 

Then you could lazily create a User object if the Message->getFromUser() method was called.

 

Basic layout:

 

class Message {

 

    private $data = array();

 

    public function __construct($data) {

        $this->data = $data;

    }

 

    public function getFromUser() {

        if(!isset($this->data['from_object'])) $this->data['from_object'] = new User($this->data['receivedfromuserid']);

        return $this->data['from_object'];

    }

 

}

 

 

 

If you wanted to get really fancy with it you could even have a lazy registry for User objects that would basically force the script to only have 1 user object per user id at a time (everything would be references to the object stored inside the registry).

Link to comment
https://forums.phpfreaks.com/topic/169391-opinions-mvc/#findComment-893880
Share on other sites

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.