如何在AppModel
中获得当前模型名称?
我有这个代码验证密码和确认密码。但我想把它放在AppModelp
:
function isSameAs($check, $field) {
if( $check === $this->data['User'][$field] ) {
return true;
}
else {
return false;
}
}
我用的是CakePHP 2
您最好使用$this->alias
(参见API的模型)。使用@Ben Lee的建议,这将是:
function isSameAs($check, $field) {
return $check === $this->data[$this->alias][$field];
}