2010年8月22日星期日

[fw-mvc] Re: Centralized Stack/Broker or something for Models

Hi Dolf,

At once I had my models as singletons. But then the wise men said that
singleton is evil. =)
So I try not to use singletons though my current goal is basicly working
similar as singeletons.

But now I can any time make a new instance of my model if needed... But
basicly I'm using
my stack of models (array) in my application bootstrap.

br, Marko


-----
br,
--------------------------
Marko Korhonen
Technical Consultant
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Centralized-Stack-Broker-or-something-for-Models-tp2333975p2334095.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Re: Centralized Stack/Broker or something for Models

All my mappers are simply a singleton, meaning that once instantiated
there's only one instance per class.

If you want to read more about models etc in somewhat more complex
situations you can also read this (free, online) book:
http://www.survivethedeepend.com/

Dolf
--Freeaqingme

On Sun, Aug 22, 2010 at 10:31 AM, Marko78 <marko.korhonen@gmail.com> wrote:
>
> Hi Andreas,
>
> All my objects are cached so db queries are only made when cache is deleted
> or cache valid time is passed.
> If row objects are updated, cache will be rebuild on that object. This way I
> don't have to do so much queries with join (though some of my lists of
> course use them).
>
> And my models are NOT DbTable objects. So Model > DbTable -> Row and so
> on...
> or some other datasource e.g. Model > ACL or Model > Twitter account or
> Model > XML-file...
>
> br, Marko
>
> -----
> br,
> --------------------------
> Marko Korhonen
> Technical Consultant
> --
> View this message in context: http://zend-framework-community.634137.n4.nabble.com/Centralized-Stack-Broker-or-something-for-Models-tp2333975p2334035.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>

[fw-mvc] Re: Centralized Stack/Broker or something for Models

Hi Andreas,

All my objects are cached so db queries are only made when cache is deleted
or cache valid time is passed.
If row objects are updated, cache will be rebuild on that object. This way I
don't have to do so much queries with join (though some of my lists of
course use them).

And my models are NOT DbTable objects. So Model > DbTable -> Row and so
on...
or some other datasource e.g. Model > ACL or Model > Twitter account or
Model > XML-file...

br, Marko

-----
br,
--------------------------
Marko Korhonen
Technical Consultant
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Centralized-Stack-Broker-or-something-for-Models-tp2333975p2334035.html
Sent from the Zend MVC mailing list archive at Nabble.com.

RE: [fw-mvc] Re: Centralized Stack/Broker or something for Models

Hello Marko,


but then, what should this broker do, actually? Maybe you are looking for a way to work with models where in some cases you are only interested in retrieving persisted data (where actually, you only need the data, let's say as an array structure), needed only for rendering that data, while in other places you actually need model class functionality, i.e., when you're modifying data in your models and want these changes to persist, like, when you want to call your models' save() method, for example.

So, when you want to render a list of news articles along with author data, it would make more sense to query this data using joins, rather then fetching authors one by one and wasting resources by instantiating model objects you don't need.

Also, maybe you want to take a look at Doctrine (http://www.doctrine-project.org).


Best regards,

Andreas

Best regards,


Andreas

Re: [fw-mvc] Re: Centralized Stack/Broker or something for Models

Hi Marko,

It will give you some insights in how to develop you zend application. 
In the book the author builds a web application, but not in an easy way.
It really explains design descisions and ways to solve common problems.
So far it helped me a lot.



On Sun, Aug 22, 2010 at 9:47 AM, Marko78 <marko.korhonen@gmail.com> wrote:

Hi,

I also use my models this way (init method in controllers). But I have so
many other places where models are used.

For example:

We are in news module (News_IndexController and listAction):

News_Model_Article is instantiate in init method of News_IndexController.
All fine.

So my list will have 10 News_Model_DbTable_Row_Article row objects. So all
news articles have author aka user. So in my row object I have method
getAuthor() which will instantiate new User_Model_User and get user by it's
method getUser($id). So every news article row will make it's own instance
of User_Model_User model which seems vain.

br, Marko

-----
br,
--------------------------
Marko Korhonen
Technical Consultant
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Centralized-Stack-Broker-or-something-for-Models-tp2333975p2334018.html
Sent from the Zend MVC mailing list archive at Nabble.com.



[fw-mvc] Re: Centralized Stack/Broker or something for Models

Hi,

I also use my models this way (init method in controllers). But I have so
many other places where models are used.

For example:

We are in news module (News_IndexController and listAction):

News_Model_Article is instantiate in init method of News_IndexController.
All fine.

So my list will have 10 News_Model_DbTable_Row_Article row objects. So all
news articles have author aka user. So in my row object I have method
getAuthor() which will instantiate new User_Model_User and get user by it's
method getUser($id). So every news article row will make it's own instance
of User_Model_User model which seems vain.

br, Marko

-----
br,
--------------------------
Marko Korhonen
Technical Consultant
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Centralized-Stack-Broker-or-something-for-Models-tp2333975p2334018.html
Sent from the Zend MVC mailing list archive at Nabble.com.

2010年8月21日星期六

Re: [fw-mvc] Centralized Stack/Broker or something for Models

Hi Marko,

Interesting question. I don't have a clear answer for you.
But I try to instantiate my models in the init function of my controller and try to use it as a property of my controller class. This way I instantiate my model class max once per controller. 

I am curious what others have to say about your question.

Regards

J. Sanders

On Sun, Aug 22, 2010 at 6:24 AM, Marko78 <marko.korhonen@gmail.com> wrote:

Hi all,

I have application which have grown a little bit complex. I use models with
DbTables and Rows and so on.
For example, my module "user" has model User_Model_User in models subfolder,
which has various methods conserning user.

Now when my application has grown and turned complex, I have noticed that I
declare my models here and there all over again during the request.
$contentModel = new Content_Model_Content; is been called in many places
during some request on my application. Only "design pattern" I use for
models is "fat models, thin controllers", so I try to write all operations
to my model instead of writing them to my controllers.

So I was thinking, am I wasting resources? Declaring the same class over and
over again in the same request. Should I have somekind of centralized stack
where to register my Models when needed and the next time the Model is
needed it could be get from this centralized stack?

Model has created a lot of discussion before and it's role seems to be
blurred for many people (and for my self too). Let me know what you think of
this, and if you have done some wise solutions with models, I hope you can
share your solution here.

ps. now I have a solution where I have stack of Models in my Application
Bootstrap which I'll interact from action helper, view helper and from
models too.

-----
br,
--------------------------
Marko Korhonen
Technical Consultant
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Centralized-Stack-Broker-or-something-for-Models-tp2333975p2333975.html
Sent from the Zend MVC mailing list archive at Nabble.com.



--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489