for the right syntax to use near 'get_all_active_cities' at line 1
This error message means this code was executed:
$modelClass->get_all_active_cities();
However the model class does not have that method, and is instead passed to mysql as a query because that's how unhandled methods are implemented.
Either there is a typo in the method name, or $modelClass is not the class you think it is
If you change your controller code like so:
function get_cities(){
debug(get_class($this->City)); //
die;
}
And see "AppModel" then your model class is not being used at all - typical reasons for that are:
- The model file name is not correct
- The model file is in the wrong folder
That's not a normal way to write model code
Having a method named get_all_active_cities that is just a simple find isn't really helpful. It's not encapsulating complexity, or making it clearer what the code does, arguably it makes the code harder to read since it's hiding something so simple. Consider simply using equivalent find:
function get_cities(){
$params = [
'conditions'=>[
'City.status'=>1
]
];
$list_cities = $this->City->find('all',$params);
...
}
Another alternative is to create a finder method so that the find logic is available in exactly the same way as the standard finders i.e.
function get_cities(){
$list_cities = $this->City->find('allActive');
...
}
With:
class Article extends AppModel {
public $findMethods = array('allAcctive' => true);
protected function _findAllActive($state, $query, $results = array()) {
if ($state === 'before') {
$query['conditions'][$this->alias . '.status'] = 1;
return $query;
}
return $results;
}
}
The benefit here is that the above finder is used in exactly the same way as the other finder methods.
If this is a condition to be applied to all finds, also consider using a behavior with a beforeFind callback to always apply that condition for you.