Re: MVC Design Question

2009-03-13 Thread mark_story

On Mar 11, 11:51 pm, Alex Jeffery alexanderjeff...@gmail.com wrote:
 Hi,

Hi,


 (Fat Model)
 1. The controller calls a custom function on the Users model. Eg
 registerUser($formData)
 2. The User model validates and saves the new user.
 3. The user model then calls the Portfolio model to create a new
 portfolio for the new user.
 4. The Portfolio model calls the Currency model to get the default
 currency and creates the new portfolio for the new user.

 The advantage I can see to the Fat Model way is that the logic for
 registering a new user is all in one spot.
 So if I have many controllers that need to register a new user I can
 just use the same code.

 Is this on the right track?

Yes, this is the route to go.  You will get more code reuse out of
this plan, plus when you get around to writing unit tests, Model tests
are easier to write than controller tests.  So its win more.  For, if
it involves manipulating data it goes into a model, If it involves
pulling params from the request or application/user flow it goes into
the controller.

-Mark
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



MVC Design Question

2009-03-12 Thread Alex Jeffery

Hi,

I am building a small cake application to learn MVC and cakePHP.
I have a question about where to put business logic, I have read that
controls should be skinny and models should be fat. Eg the business
rules should live in the models.

In my application I have the following models User, Portfolio,
Currency.
A user has 1 portfolio which has 1 currency. When I register a user I
would like to create their portfolio and assign it the default
currency.

My question is where to do the creation of the portfolio?
(Fat Controller)
1. Call the User model to create a new user.
2. Call the Currency model to get the default currency.
3. Call the Portfolio model to create a new portfolio for the new user
with the default currency.

Or

(Fat Model)
1. The controller calls a custom function on the Users model. Eg
registerUser($formData)
2. The User model validates and saves the new user.
3. The user model then calls the Portfolio model to create a new
portfolio for the new user.
4. The Portfolio model calls the Currency model to get the default
currency and creates the new portfolio for the new user.

The advantage I can see to the Fat Model way is that the logic for
registering a new user is all in one spot.
So if I have many controllers that need to register a new user I can
just use the same code.

Is this on the right track?

Thanks,
Alex

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: MVC Design Question

2009-03-12 Thread Martin Westin

+1 for your version 2 (Fat Model). It is the way I do things for
similar cases.

Sometimes you want to do it beforeSave (this model should be saved
only if the other model can be created)
and other times afterSave when things are the other way around.

afterSave has a helpful parameter so you can know if this was a
creation or an update.
function afterSave($created) {
}

In beforeSave you would have to check for the existance of an id in
the data (= an update) or not.



On Mar 12, 4:51 am, Alex Jeffery alexanderjeff...@gmail.com wrote:
 Hi,

 I am building a small cake application to learn MVC and cakePHP.
 I have a question about where to put business logic, I have read that
 controls should be skinny and models should be fat. Eg the business
 rules should live in the models.

 In my application I have the following models User, Portfolio,
 Currency.
 A user has 1 portfolio which has 1 currency. When I register a user I
 would like to create their portfolio and assign it the default
 currency.

 My question is where to do the creation of the portfolio?
 (Fat Controller)
 1. Call the User model to create a new user.
 2. Call the Currency model to get the default currency.
 3. Call the Portfolio model to create a new portfolio for the new user
 with the default currency.

 Or

 (Fat Model)
 1. The controller calls a custom function on the Users model. Eg
 registerUser($formData)
 2. The User model validates and saves the new user.
 3. The user model then calls the Portfolio model to create a new
 portfolio for the new user.
 4. The Portfolio model calls the Currency model to get the default
 currency and creates the new portfolio for the new user.

 The advantage I can see to the Fat Model way is that the logic for
 registering a new user is all in one spot.
 So if I have many controllers that need to register a new user I can
 just use the same code.

 Is this on the right track?

 Thanks,
 Alex
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---