First of all, $data is a local variable, so it won't change anything
in invalidFields().
Second, even if you modify $this->data, it will not be used in invalidFields().

In the code below, after first if (empty($data)), there is passed data
or copy of $this->data.
Then at if (!empty($data)), $data is never empty because it has either
passed data or copy of $this->data at the beginning, and $data won't
change anyway.

function invalidFields($data = array()) {
    if (empty($data)) {
        $data = $this->data;
    }

    if (!$this->beforeValidate()) {
        return false;
    }

    if (!isset($this->validate)) {
        return true;
    }

    if (!empty($data)) {
        $data = $data;
    } elseif (isset($this->data)) {
        $data = $this->data;
    }

Populating $this->data is mentioned in here, but at the end, nate
mentioned that "We will no longer support calling Model::validates or
Model::invalidFields with parameters. You should set( ) the data, then
call validates( ) or invalidFields( )."
https://trac.cakephp.org/ticket/1040

So I guess we are not supposed to pass data, but set before call.
Still, changes in $this->data in beforeValidate() won't affect in
invalidFields().

I think the fix of using array_merge in here is still needed.
It said it is fixed, but I don't see the array_merge in the fix.

I believe the change in $this->data should be taken in
invalidFields(), so is this a bug?
I've been wondering about this code for a while, so please let me know
I understand it incorrect.

So back to your problem, I am not sure there is a way to get the
changes from beforeValidate(). Either you do that before calling
save() or invalidFields(), or apply the array_merge() fix in
invalidFields().

One more thing, if you are calling parent::beforeValidate(), and if
you have any validation there, I think you should check and return if
it fails:
    if (!parent::beforeValidate()) {
        return false;
    }

I really want to know about the invalidFields code, so if someone has
any idea, please let me know.

Sohei

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to