Tuesday 15 March 2011

php - Using find('list') in Cakephp 1.3 with custom fields -



php - Using find('list') in Cakephp 1.3 with custom fields -

i'm working in cakephp 1.3 project. have problem retrieving info database using find('list'). before lastly alter had code:

$listahabilidades = $this->habilidad->find('list',array('fields'=>array('id','habilidad'),'order'=>array('habilidad'))));

this command gives me next array:

array ( [40] => bicicleta [42] => enganches de poleas [28] => escalada [43] => transfer [41] => 4x4 [53] => administración linux [72] => Ángeles [59] => baile flamenco [57] => baloncesto [39] => barranquismo [66] => cante flamenco [30] => conducción [52] => consola linux [80] => cuarta prueba [75] => demonios [84] => esgrima [58] => futbol [76] => limpiar [77] => limpiar2 [54] => linux [27] => montañismo [60] => ms office [65] => natación [45] => patinaje [56] => pc [78] => probar [44] => programación [82] => protocolo [81] => quinta prueba [63] => tenis [79] => tercera prueba [83] => triatlón [55] => w8 [51] => xp [64] => zapateado )

but had problem because info can have spaces @ begining of field 'habilidad' , want info without , order them without them. changed command to:

$listahabilidades = $this->habilidad->find('list',array('fields'=>array('id','trim(habilidad.habilidad)'),'order'=>array('trim(habilidad.habilidad)'))));

it gives me next array:

array ( [41] => [53] => [72] => [59] => [57] => [39] => [40] => [66] => [30] => [52] => [80] => [75] => [42] => [28] => [84] => [58] => [76] => [77] => [54] => [27] => [60] => [65] => [45] => [56] => [78] => [44] => [82] => [81] => [63] => [79] => [43] => [83] => [55] => [51] => [64] => )

how can list trimmed (without loops)?

can add together virtual field model:

public $virtualfields = array( 't_habilidad' => 'ltrim(habilidad.habilidad)' );

then utilize

$listahabilidades = $this->habilidad->find('list', array('fields'=>array('id','habilidad'), 'order' => array('t_habilidad'))));

php cakephp

No comments:

Post a Comment