views:

34

answers:

1

Hi,

I created a enterprise system model from a class diagram and converted it php object oriented code.

What I have now is just an empty model, it's able to relate and the connections are handled. Now the next step is ahead. I have a database and have to put the object into the database.

Now there is a lack of experience on my side. I have the model and since php renders a view and makes one time requests to render the view I'm a bit confused. It can't be possible to load all my entities out of the database and fill my model in memory and then use it because it would be way to large.

Does anybody know any ways to load just the needed data in my model and then use it? Maybe suggestions of a book or article?

Thanks!

A: 

It sounds like you are running a "MV" (which doesn't exist) rather than "MVC" design pattern.

What's happened to your controller? Your controller should route the request to the model entity which is required for this particular view and then you can use the response as you require.

If your model represents information which is too large, then you are doing something wrong. You should consider lazy-loading your data, and only loading what is strictly neccessary. Naturally your controller will decide this and route everything to your model.

Edit in response to comments

You have several methods. If you are using Zend_Db_Table_Abstract then you subclass this class and use it as your model. This is probably the easiest. Then you just use it as your model. Set the $_name = "myComments" and then just create a method called getComments.

In your method on in your subclass of Zend_Db_Table_Abstract, you can then create your $select. Then you just return the response from your model.

So

    $rows = $table->fetchAll($select);

And then just return $rows; You will then get your $rows back in your controller. You have loaded your model in your controller by $model = new Comments(); and then do the fetch using $result = $model->getComments();

Its a bit of a mismatch ,but that should show you how you should do it. You just need to create your model now.

Laykes
Hmm there is a controller. I'm using Zend Framework with MVC.I think I explained it wrong and am thinking my model is wrong. The dataloading should happen in the model so I might just ask:How to load data into the objects required by the controller.To explain in short: I have a entity that is connected with an account and a comment.How to load the comments into the entity out of my database?
baklap