incubator icon indicating copy to clipboard operation
incubator copied to clipboard

Traversing over mongdb results raise error because of missing \Countable implementation when using volt render engine.

Open noone-silent opened this issue 2 years ago • 0 comments

Expected and Actual Behavior

Trying to iterate the result of a mongdb find query raises an error because of missing implementation of \Countable interface in combination with volt render engine.

Rendered volt template

<?php if ((is_array($results) || ($results) instanceof Traversable)) { ?>
    <?php $v129769671215234269051iterator = $results; $v129769671215234269051incr = 0; $v129769671215234269051loop = new stdClass(); $v129769671215234269051loop->self = &$v129769671215234269051loop; $v129769671215234269051loop->length = count($v129769671215234269051iterator); $v129769671215234269051loop->index = 1; $v129769671215234269051loop->index0 = 1; $v129769671215234269051loop->revindex = $v129769671215234269051loop->length; $v129769671215234269051loop->revindex0 = $v129769671215234269051loop->length - 1; ?>
    <?php foreach ($v129769671215234269051iterator as $results) { ?>
        <?php $v129769671215234269051loop->first = ($v129769671215234269051incr == 0); $v129769671215234269051loop->index = $v129769671215234269051incr + 1; $v129769671215234269051loop->index0 = $v129769671215234269051incr; $v129769671215234269051loop->revindex = $v129769671215234269051loop->length - $v129769671215234269051incr; $v129769671215234269051loop->revindex0 = $v129769671215234269051loop->length - ($v129769671215234269051incr + 1); $v129769671215234269051loop->last = ($v129769671215234269051incr == ($v129769671215234269051loop->length - 1)); ?>
         // ...
    <?php } ?>
<?php } ?>

Volt template

{% if results is iterable %}
    {% for result in results %}
    {% endfor %)
{% endif %}

Solution would be to implement the \Countable interface.

Details

  • Phalcon Framework version: 4.1.0
  • Phalcon Incubator version: phalcon/incubator-mongodb:v1.0.1
  • PHP Version:7.4.28
  • Operating System: Linux (debian)
  • Server: Other
  • Other related info (Database, table schema): mongodb, any

noone-silent avatar Mar 03 '22 02:03 noone-silent