Get the model name for implementing the reusable method in AppModel in CakePHP

How to get current model name in AppModel ?

I have this code for password confirmation and password confirmation. But I would like to put it in AppModelp :

 function isSameAs($check, $field) { if( $check === $this->data['User'][$field] ) { return true; } else { return false; } } 

I am using CakePHP 2.

+4
source share
1 answer

It is best to use $this->alias (see the API for the model ). Using the @Ben Lee suggestion, this will be:

 function isSameAs($check, $field) { return $check === $this->data[$this->alias][$field]; } 
+6
source

Source: https://habr.com/ru/post/1384089/


All Articles