Search code examples
twigslimphpactiverecord

Slim Framework / php active record / twig conundrum, find all where field not equal to


Trying to get to grips with slim framework and phpactive record. Have searched the docs, here and google to no avail and tried several things.

I would like to retrieve all items from a table where a field is not set to a particular enumerator. Sounds simple and it should be.

    $data['labels'] = Label::find()->where('printed' != 'Y')->all();

The above fails with: Message: Couldn't find Label without an ID. I have also tried:

    $data['labels'] = Label::find('all','printed' != 'Y');

It just returns one record rather than all that meet the criteria.

In my twig template I have tried (which does nothing):

    {% for label in labels %}
     <td>{{ label.id }}</td>
     <td>{{ label.title }}</td>
     <td>{{ label.address }}</td>
    {% endfor %}

and (which prints the single record:

     <td>{{ labels.id }}</td>
     <td>{{ labels.title }}</td>
     <td>{{ labels.address }}</td>

thanks for any pointers.


Solution

  • I believe PHP ActiveRecord syntax should be one of the following:

    Label::find("all", array("conditions" => array("label != ?", "Y")));
    Label::all(array("conditions" => array("label != ?", "Y")));