Monday, May 17, 2010

Re: User errors and fat model, skinny controller

Validation and validation errors. You always have form on such pages,
so you can use $form->error(). Existence of field in DB is not
necessary for validation. You can just call $this-
>invalidate('file_format') in model, write there appropriate error
message, and output it on page.

On May 18, 6:27 am, calvin <cal...@rottenrecords.com> wrote:
> So since I've started trying to implement the fat model, skinny
> controller MVC pattern, I've continuously run into one issue--the
> problem of dealing with user errors.
>
> Fat model, skinny controller is great as it predisposes developers
> towards a top-down development style that produces self-documenting
> and more maintainable code. But I've found that, the more I try to
> move the business logic to the model, the harder it is for me to
> display detailed error messages or otherwise alter the view in
> response to different use cases.
>
> For example, if one is trying to write an action that allows the user
> to upload a sales report, you could write something like:
> function upload() {
>     if (!empty($this->data) {
>          if ($this->Report->upload($this->data) {
>              $this->Session->flash('Sales report uploaded and
> processed.');
>              $this->redirect(...);
>          } else {
>              $this->Session->flash('Sales report could not be
> processed.');
>          }
>     }
>
> }
>
> And in Report::upload() you might save the uploaded file and process
> the sales data it contains.
>
> But what if the file was successfully uploaded, but could not be
> processed for some reason? E.g. how do you tell the user that the file
> uploaded correctly, but its contents are incorrect? Or how do you tell
> the user that the file uploaded correctly, but one of the products
> referenced by the sales report is not in the database and must be
> added first?
>
> Has anyone else encountered this problem? How have others overcome it?
> Do you throw lots of exceptions or just return an array that includes
> error/status info?
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions.
>
> 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+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate