2010年12月23日星期四

Re: [fw-mvc] Best practices to organize Models/Controllers

Hello Fernando,

You might want to read up on how to implement a service layer. Here are few
links to get you pointed in the right direction:

http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/
http://zend-framework-community.634137.n4.nabble.com/Model-data-source-data-mapper-and-service-layer-td1885770.html

http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html

It is advisable that your entity objects, subscriber, for example, only know
what they absolutely need to. They should be clueless to how they are persisted
and have a simple api to modify their properties. Service classes can be used
for code that doesn't seem to fit in any model entity.

Regards,

David

________________________________
From: Fernando Morgenstern <contato@fernandomarcelo.com>
To: Zend MVC <fw-mvc@lists.zend.com>
Sent: Thu, December 23, 2010 7:29:57 AM
Subject: [fw-mvc] Best practices to organize Models/Controllers

Hello,

I am looking for some input about best practices in models/controllers.

The application is still pretty simple, but i would like to make it right from
the beginning. I have two actions:

1) I have to select a specified subscriber that is active ( active = 1 in
database )
2) I have to select a specified subscriber, it does not matter if active or not.

My initial approach was this in controller:

$model = new Model_Subscriber();
$model->fetchAll(array(
'email = ?' => $email,
'active = 1'
));

I soon realized that this is bad since i am writing SQL and business logic in
controller. So i created two functions in model:

1) getActiveSubscriberQuery($email)
2) getSubscriberQuery($email)

Both return a Zend_Db_Select, which i can use in fetchAll().

My question: Is this the best way to do things? I mean, yhe application might
get complex and i am worried about having lots and lots of functions for each
type of query in model.

Regards,

Fernando Morgenstern
contato@fernandomarcelo.com

没有评论: