How do I convert an integer to string in CakePHP? -
in cakephp app when try data this:
$this->loadmodel('radio'); $posts = $this->radio->find('all');
the integers displayed strings (in debug) :
'radio' => array( 'idsong' => '4', 'name' => 'batman', 'title' => 'batman theme song' ),
why? type int in db. need integers correctly displayed in json files
not sure if there's straightforward solution, change model data using afterfind
something like
public function afterfind($results, $primary = false) { foreach ($results $key => $val) { if (isset($val['radio']['idsong'])) { $results[$key]['radio']['idsong'] = (int)$results[$key]['radio']['idsong']; } } return $results; }
Comments
Post a Comment