I generally use validation errors whenever I can. And that's indeed
how I deal with file extension issues. The problem I was trying to get
across is situations where you need to do more than just display a
simple error message.

A more concrete example would be, for instance, if you were trying to
generate a royalty statement for an artist. The user would select the
artist and the accounting period to process data from, and the
application looks up all the sales data and applies the royalty rates
for that artist. But if no royalty rates have been inputted for that
artist, then you want to redirect the user to the rates creation
action or just render a form that allows rates to be created for that
artist.

Another example which I alluded to before would be when trying to
display detailed status messages to the user after processing bulk
data. In my case, I have a model method called process() which returns
the number of sales figures processed or false if a fatal error
occurred. But in addition to reporting the number of sales figures
processed, I also wanted to display information about non-fatal
errors, such as products listed in the spreadsheet that are not in our
product database. If the processing were done in the controller, I
would simply set a view variable containing an array of all the
missing products (and additional info like the artist or album it
belongs to). But after moving the code to my Spreadsheet model, I had
to store that supplementary info in a new model property,
Spreadsheet::missingProducts.

I suppose you could still create fake fields and invalidate them to
send messages from model to controller, but many of these situations
aren't necessarily categorized as form validation per se, and this
would not work well for non-string data.

On May 17, 9:04 pm, "Dr. Loboto" <[email protected]> wrote:
> 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 <[email protected]> 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.organdhelp 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 [email protected]
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en
>
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected] 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 [email protected]
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

Reply via email to