xpdo
xpdo copied to clipboard
Make it possible to find key/value pairs
I use CakePHP at work and I love how easy it is to find key/value pairs.
This would also be very useful in for example MODX. It would make it easier to show the "display name" of a system setting (like the name of the default template) instead of the value for the primary key.
It is often useful to generate an associative array of data from your application’s data. For example, this is very useful when creating
$query = $articles->find('list'); $data = $query->toArray(); // Data now looks like $data = [ 1 => 'First post', 2 => 'Second article I wrote', ];
I do not understand the example you've provided. That seems like a simple convenience method for "listing" the page titles. You can quickly build a PDO query in xPDO to do this as well, so a little more context would be helpful here.
You are right, I should give a bit more context. I will do that later this week.
In MODX for example there are various places where a "displayField" would be useful.
For example, templates:
In most cases we always want to show it's name. In dropdown, system settings etc. Yet in system settings it now displays the value of the "primary key". If we could define a displayField next to a primary key we have the possibility to be consistent in the way we show values. The "primary key" could then be used as value while the "displayField" is being used for the label.
This way the "model" of the object defines how it should be displayed making it easier for others.
And yes, its a convenience method but I'm sure it would be a great addition for a lot of snippet/chunks developers.
How does that work when you wish to localize the component for another language? Having a singular displayField would seem to lock it to one language.
In CakePHP they have behaviors. For entity/object translations you can use the TranslateBehavior. I have to dig a bit deeper into xPDO to check how this can be accomplished in xPDO.
Of course I don’t want xPDO to become CakePHP, but I do find it handy how they solve this.