Re: model methods as they relate to business logic

2008-02-21 Thread the_woodsman

Hi Josh,

I don't understand entirely, but I reckon the Model is the appropriate
way to go.

If you google for "fat models / skinny controllers", I think it'll
relieve any doubts you have about putting this kind of stuff in the
modell :)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: model methods as they relate to business logic

2008-02-21 Thread Dardo Sordi Bogado

Don't bump, please.

On Thu, Feb 21, 2008 at 4:22 PM, vendejp <[EMAIL PROTECTED]> wrote:
>
>  bump... anyone?  thx
>
>
>
>  On Feb 19, 4:51 pm, vendejp <[EMAIL PROTECTED]> wrote:
>  > Im used to thinking of model objects like business objects, so if I
>  > perform some work on an object, I want to put the method in the biz
>  > object... as an example when I have a model with 2 fields: "fname" and
>  > "lname".
>  >
>  > Rather than always doing a check of something like this in the
>  > controller (possibly lots of places):
>  >
>  > $user = $this->User->read(null, 1);
>  > if(trim($user['User']['fname'])=='' || trim($user['User']
>  > ['lname'])=='')){
>  >// do something
>  >
>  > }
>  >
>  > I would prefer to do this so that if I need to change the logic I do
>  > it in one place:
>  > if($this->User->isValid(1)){
>  > // do something
>  >
>  > }
>  >
>  > The model would have something like:
>  > function isValid($id=null){
>  > $this->id = $id;
>  > $user = $this->User->read();
>  > if(trim($user['User']['fname'])=='' || trim($user['User']
>  > ['lname'])=='')){
>  > return false;
>  > }
>  > return true;
>  >
>  > }
>  >
>  > Maybe I loop through the results of a find() and I want to call this
>  > method over and over... I dont want it to do a $this->User->read()
>  > over and over.  As a result, I could put this function in the model
>  > but just pass in the array representation of the object.
>  >
>  > I end up with something like this in the model:
>  >
>  > function isValid($user=null){
>  > if(trim($user['User']['fname'])=='' || trim($user['User']
>  > ['lname'])=='')){
>  > return false;
>  > }
>  > return true;
>  >
>  > }
>  >
>  > What is the best practice for logic like this?  That is, logic that
>  > shouldnt go into a component because it is specific to a model?
>  >
>  > Thanks in advance
>  >
>

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



Re: model methods as they relate to business logic

2008-02-21 Thread vendejp

bump... anyone?  thx

On Feb 19, 4:51 pm, vendejp <[EMAIL PROTECTED]> wrote:
> Im used to thinking of model objects like business objects, so if I
> perform some work on an object, I want to put the method in the biz
> object... as an example when I have a model with 2 fields: "fname" and
> "lname".
>
> Rather than always doing a check of something like this in the
> controller (possibly lots of places):
>
> $user = $this->User->read(null, 1);
> if(trim($user['User']['fname'])=='' || trim($user['User']
> ['lname'])=='')){
>// do something
>
> }
>
> I would prefer to do this so that if I need to change the logic I do
> it in one place:
> if($this->User->isValid(1)){
> // do something
>
> }
>
> The model would have something like:
> function isValid($id=null){
> $this->id = $id;
> $user = $this->User->read();
> if(trim($user['User']['fname'])=='' || trim($user['User']
> ['lname'])=='')){
> return false;
> }
> return true;
>
> }
>
> Maybe I loop through the results of a find() and I want to call this
> method over and over... I dont want it to do a $this->User->read()
> over and over.  As a result, I could put this function in the model
> but just pass in the array representation of the object.
>
> I end up with something like this in the model:
>
> function isValid($user=null){
> if(trim($user['User']['fname'])=='' || trim($user['User']
> ['lname'])=='')){
> return false;
> }
> return true;
>
> }
>
> What is the best practice for logic like this?  That is, logic that
> shouldnt go into a component because it is specific to a model?
>
> Thanks in advance
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---