php - Using column names when generating JSON in Propel -


when using tojson() on objectcollection names of properties based on php-names. instance:

for column type_name json property becomes typename, etc.

is there way make propel use name of field/column instead?

if don't mind using json_encode, try using object's toarray() arguments:

use map\audittablemap tablemap;  $something = new something(); $something->setsomecolumnvalue("value"); echo json_encode($something->toarray(somethingmap::type_fieldname)); 

output:

{"some_column_value": "value"} 

in other words, use argument <objectname>map::type_fieldname output array column names.

the docs amazing, they're quite confusing navigate. found following comment 1 of generated models in project. version 2.0@dev, i'm using; note it may differ in version. (i'd suggest looking @ docs more formal guidance, can take peek @ models too.)

/**  * exports object array.  *  * can specify key type of array passing 1 of class  * type constants.  *  * @param     string  $keytype (optional) 1 of class type constants tablemap::type_phpname, tablemap::type_camelname,  *                    tablemap::type_colname, tablemap::type_fieldname, tablemap::type_num.  *                    defaults tablemap::type_phpname.  * @param     boolean $includelazyloadcolumns (optional) whether include lazy loaded columns. defaults true.  * @param     array $alreadydumpedobjects list of objects skip avoid recursion  * @param     boolean $includeforeignobjects (optional) whether include hydrated related objects. default false.  *  * @return array associative array containing field names (as keys) , field values  */ 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -