XF 2.1 Can we give a fancy name to a database column in an entity?

abdfahim

Well-known member
Can we give a fancy name to a database column in an entity :)? Like we can do during SQ query SELECT `db_column_1` as `Fancy Column Name` from db_table ......
PHP:
$structure->columns = [
            'db_column_1' => ['type' => self::STR, 'nullable' => true, 'default' => null, 'title' => 'Fancy Column Name']
];
 
Not really. You can use getters if you want to access the column on the entity via an alias, but I don't really know what purpose that would serve.
 
but I don't really know what purpose that would serve.
A simplified example, if my column names are "total_cost", "total_area" etc., I would like to list them as

Total Cost = {$results.total_cost}
Total Area= {$results.total_area}

So, if I could give an alias to the fields, I could use a for loop, otherwise I have to manually write down each line (or pass an array containing corresponding aliases from my controller class).
 
I wouldn't recommend that, as it can't be translated (unless that's not a concern for you). You could use phrase groups for this purpose though: my_addon_fields.{$column}
 
Sorry, but what do you mean by phrase group? Can we define something like that in XF phrase system? Or you meant to pass an array like my_addon_fields = ["total_cost" => "Total Cost"] from PHP controller class?
 
Back
Top Bottom