Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created December 16, 2010 12:34
Show Gist options
  • Save nojimage/743348 to your computer and use it in GitHub Desktop.
Save nojimage/743348 to your computer and use it in GitHub Desktop.
こうですかわかりません ><
<?php
/**
* Allways nojimage!
*/
class NojimageBehavior extends ModelBehavior {
public function beforeSave($model) {
foreach ($model->data[$model->alias] as $key => $value) {
$schema = $model->schema($key);
if (in_array($schema['type'], array('string', 'text'))) {
$model->data[$model->alias][$key] = 'nojimage';
}
}
return true;
}
public function afterFind($model, $results, $primary) {
if (Set::numeric(array_keys($results))) {
for ($i = 0; $i < count($results); $i++) {
foreach ($results[$i][$model->alias] as $key => $value) {
$results[$i][$model->alias][$key] = 'nojimage';
}
}
} else {
foreach ($results[$model->alias] as $key => $value) {
$results[$model->alias][$key] = 'nojimage';
}
}
return $results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment