PHP Call-Back-Funktionen verwenden
Kennt ihr Call-Back-Funktionen? Z.b. wenn es heißt Daten neu zu formatieren, z.b. in einer Attribute-Liste, dann sind Call-Back-Funktionen echt nützlich. Warum auch immer werden Callback-Funktion nicht so oft benutzt wie es sinnvoll wäre, aus diesem Grund ein kurzes Blog-Post zu der Thematik.
So geht’s:
$callback = '_test' . uc_words($attributeCode, '');
if (method_exists($this, $callback)) {
$entry = $this->$callback($attribute);
if (!empty($entry)) {
$data[$attributeCode] = $entry;
}
}
protected function _testColor($attributeCode)
{
// do something
//return data
$return $data[$attributeCode] = array(
'value' => 'attribute value'
);
return $data;
}
Wenn euch der Tipp geholfen hat, bitte diesen Artikel auch bei Google+ und Facebook teilen, danke für euren Support!

