cakePHPのafterFind

findで取得するデータに表示用のテキストなど付けたい場合はModelでafterFind。

	public $options = array(
		'flag' => array(
			1 => 'カテゴリA',
			2 => 'カテゴリB',
		),
	);
	public function afterFind($results) {
		foreach ($results as $key => $val) {
			if (isset($results[$key]['User']) && is_array($results[$key]['User'])) {
				$val = $results[$key]['User']['flag'];
				$results[$key]['User']['flag'] = array();
				$results[$key]['User']['flag']['val'] = $val;
				$results[$key]['User']['flag']['str'] = $this->options['flag'][$val];
			}
		}
		return $results;
	}

You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

コメントを残す

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>