Skip to content

Make it possible to find key/value pairs #141

Open

Description

@JoshuaLuckers

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.

Example from CakePHP:

It is often useful to generate an associative array of data from your application’s data. For example, this is very useful when creating elements $query = $articles->find('list'); $data = $query->toArray(); // Data now looks like $data = [ 1 => 'First post', 2 => 'Second article I wrote', ];

Activity

  1. opengeek commented on Jun 3, 2018

    @opengeek
    Member

    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.

  2. JoshuaLuckers commented on Jun 4, 2018

    @JoshuaLuckers
    ContributorAuthor

    You are right, I should give a bit more context. I will do that later this week.

  3. JoshuaLuckers commented on Jun 9, 2018

    @JoshuaLuckers
    ContributorAuthor

    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.

  4. mkschell commented on Jun 12, 2018

    @mkschell
    Member

    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.

  5. JoshuaLuckers commented on Jun 12, 2018

    @JoshuaLuckers
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions