Skip to content

Instantly share code, notes, and snippets.

@mogya
Last active December 17, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogya/5524119 to your computer and use it in GitHub Desktop.
Save mogya/5524119 to your computer and use it in GitHub Desktop.
custom find type to get result hash without model name.
<?php
App::uses('Model', 'Model');
class AppModel extends Model {
public $findMethods = array('noModelName' => true);
protected function _findNoModelName($state, $query, $results = array()) {
if ($state == 'before') {
return $query;
} elseif ($state == 'after') {
$modelNameKey = $this->name.'.';
$resultsNoModelName = array();
$flatResult = Hash::flatten($results);
foreach ($flatResult as $key => $value){
$key = str_ireplace($modelNameKey, '', $key);
$resultsNoModelName[ $key ] = $value;
}
return Hash::expand($resultsNoModelName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment