Created
April 2, 2015 02:38
-
-
Save eberfreitas/e6e6d6755b59ed2e2fc1 to your computer and use it in GitHub Desktop.
Simple field setters for CakePHP 2.X.X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AppModel extends Model { | |
public function beforeValidate($options = array()) { | |
$this->_setupSetters(); | |
return true; | |
} | |
protected function _setupSetters() { | |
foreach ($this->data[$this->alias] as $key => $value) { | |
$methodName = '_set' . Inflector::camelize($key); | |
if (method_exists($this, $methodName)) { | |
$this->data[$this->alias][$key] = call_user_func([$this, $methodName], $value); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User extends AppModel { | |
public $displayField = 'name'; | |
protected function _setName($value) { | |
return str_rot13($value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment