Cakephp Revision behavior hurdles validation error?

631 views Asked by At

I have a CakePHP ticketing app where I am using Revision Behavior to keep revision history of each tickets. The problem I have using this behavior is, it does not display validation error messages. Here is the line I have added in the model.

public $actsAs = array('Revision' => array('limit'=>10));

When I comment this line, it displays error messages and otherwise it does not. Also, when I debug it using x-debug, I see validationErrors variable is set and has all error message values set properly.

Please shed some light here.

Edit: I am using Cake 2.1

2

There are 2 answers

4
Scott Harwell On BEST ANSWER

There are a few things that could be happening here. Too much for one to simply tell you what is happening since we don't have any of your code. However, I am pretty certain that this behavior, being that it was written in 2008, will have issues with CakePHP version 2.1, which just released its first alpha. There have been a lot of changes to the infrastructure of Cake that could cause this not to work. I'd say this would probably work with version 1.3 and definitely with 1.2, but getting support for 2.1 probably won't happen without updates.

That said, this is a behavior, which should only alter model code. So, there should be not impact (theoretically) on your view. Are you sure you are using the proper conventions in your code to display errors (even though commenting it out changes displayed messages).

I'd look for a 2.0+ compatible version of the behavior. Or, you could throw the code on Github and start to port it yourself. You may get some help from some Cake people.

1
Chris On

First, be sure to get the last version of this behavior : http://alkemann.googlecode.com/svn/trunk/models/behaviors/revision.php

for integration in CAKE 2.X, the problem comes from line 980 in the createShadowModel() function: $Model->ShadowModel->alias = $Model->alias;

The behavior gives the same alias to the base model and its shadowmodel it will save in the _revs table and that seems to mess up the validation messages. The problem is that this behavior is loaded automatically when you access your model, and the createShadowModel() function is called even if your input doesn't validate. One of the solution would be to comment out this line from createShadowModel() and then to add it only to every function in the behavior that will make an operation in the DB . There is surely a better way than that, like detecting in the setup() if there is need to go further to initialization, but couldn't find how to do it. So that's my first step towards at least allowing to use this behavior in Cake 2.X.