Hi everyone,
I have a question about data in invalidFields().
I mentioned this in response to other post, and I wonder if anyone have
answer.
It seems like the data is not passed around well in and between
invalidFields() and beforeValidate(). I know there are some tickets
related to this, but I don't think it answers to this one.
In the code below, after first if (empty($data)), $data would be 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.
In addition, beforeValidate() cannot change data to be invalidFields(),
since invalidFields() cares about $data, which can only be either
passed $data, or copy of $this->data before beforeValidate().
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 for beforeValidate() 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.
https://trac.cakephp.org/ticket/781
It said it is fixed, but I don't see the array_merge in the fix.
I think changes in $this->data should be reflected in
invalidFields(). Am I thinking wrong, or is this a bug?
I've been wondering about this for a while, so please let me know of
your opinion.
Thank you.
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
-~----------~----~----~----~------~----~------~--~---