CakePHP 2.5.4
PHP 5.5.14 
MySQL 5.1.73

I have been searching for a solution to this one for hours.  I'm not sure 
what search terms to use to find an answer to this.  
I am trying to accept an IP Address, convert it using the php builtin 
ip2long, and save it in a table.

I have a simple table:

CREATE TABLE ips (
  id CHAR(36) NOT NULL default '',
  ip INT(32) DEFAULT NULL,
  PRIMARY KEY  (id)
);


and a simple model:

class Ip extends AppModel {

public $validate = array(
'ip' => 'numeric',
);

public function beforeValidate($options = array()) {
if (isset($this->data['Ip']['ip'])) { $this->data['Ip']['ip'] = 
ip2long($this->data['Ip']['ip']); };
return true; 
}

public function afterFind($results, $primary = false) {

foreach ($results as $key => $val) {
if (isset($val['Ip']['ip'])) { $results[$key]['Ip']['ip'] = 
long2ip($results[$key]['Ip']['ip']); }
}
return $results;
}

}

I baked a standard controller and views for this model, and have made no 
changes to them.

When I enter the IP Address and click Submit, I get a little tooltip popup 
that says "Please enter a number"

I also tried changing my beforeValidate to a beforeSave, and changed the 
validation from 'numeric' to 'ip', but that had the same result...

Now,  If I alter my IP field in the table to a VARCHAR, Everything Works as 
it should,  including the validation that I have defined in the model.  The 
numeric IP value is saved without error in the VARCHAR field.


Apparently Cake is doing some kind of validation on the table data type 
Before the functions beforeValidate and beforeSave are run.   How do I 
bypass this behavior?  

TIA

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to