Tuesday, November 2, 2010

Re: Standard mechanism for telling why a record hasn't been deleted?

On Tue, Nov 2, 2010 at 10:09 AM, psybear83 <psybear83@gmail.com> wrote:
> Hi all
>
> Is there a standard mechanism for telling why a record hasn't been
> deleted?
>
> When a record isn't deleted, it just tells "Xxx was not deleted", but
> without any reason. So for example, when I'm creating a
> beforeDelete(..) hook that prevents the record from deletion, how
> should I let the user know why it hasn't been deleted?
>
> Would using a $deletionError variable be an acceptable way?
>
> function beforeDelete($cascade) {
>  if($this->hasDependentRecords()) {
>    $this->deletionError = 'record has dependent records';
>    return false;
>  }
> }
>
> And in the controller:
>
> if ($this->Post->delete($id)) {
>  ...
> } else {
>  $this->Session->setFlash('Post was not deleted because '.$this->Post-
>>deletionError);
> }
>
> What do you think about this solution? Is there a better way?

Seems reasonable. I don't know if there's anything built in.

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

No comments: