Sunday, March 17, 2013

Re: Model should be fat or thin?

It's not about counting lines, rather putting code in the right place.

There's a minimum amount of code that must be put in a controller for operating on a model to work.The meaning of fat-model, thin controller is don't do this:

    function confabulate($id) {
        $data = $this->Foo->findById($id);

        ... several lines of code later

        if ($success) {
            return $this->redirect(array('action' => 'view', $id));
        }
        return $this->redirect(array('action' => 'index'));
    }

But instead to write:

    function confabulate($id) {
        $success = $this->Foo->confabulate($id); // <- create this method
        if ($success) {
            return $this->redirect(array('action' => 'view', $id));
        }
        return $this->redirect(array('action' => 'index'));
    }

This does not apply to the blog tutorial in that there _is_ no model code in use except basic CRUD functionality.

AD

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: