Last active
December 17, 2015 00:49
-
-
Save mogya/5524119 to your computer and use it in GitHub Desktop.
custom find type to get result hash without model name.
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 | |
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