If you don't mind using json_encode
, try using the object's toArray()
with arguments:
use Map\AuditTableMap as TableMap;
$something = new Something();
$something->setSomeColumnValue("value");
echo json_encode($something->toArray(SomethingMap::TYPE_FIELDNAME));
Output:
{"some_column_value": "value"}
In other words, use the argument <ObjectName>Map::TYPE_FIELDNAME
to output an array with column names.
The docs are amazing, but they're quite confusing to navigate. I found the following comment from one of the generated models in my project. This is for version 2.0@dev
, which I'm using; note that it may differ in your version. (I'd suggest looking at the docs for more formal guidance, but you can take a peek at your models too.)
/**
* Exports the object as an array.
*
* You can specify the key type of the array by passing one of the class
* type constants.
*
* @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
* Defaults to TableMap::TYPE_PHPNAME.
* @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
* @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
* @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
*
* @return array an associative array containing the field names (as keys) and field values
*/