Cakephp $query->isEmpty() 不起作用



下面的 php if 语句不起作用。 查询(案例(为空,但在为空时不会显示 else 语句。

<?php foreach ($cases as $case): ?>
                    <?php if(!$cases->isEmpty()): ?>            
                    <tr>
                        <td><?= h($case->plaintiff) ?> </td>
                        <td><?= h($case->defendant) ?></td> 
                        <td><?= h($case->case_number) ?></td>
                        <td><?= $this->Html->link(_('View'), ['controller' => 'Cases', 'action' => 'view', $case->id], array('class' => 'btn btn-xs btn-success')) ?></td>
                    </tr>
                    <?php else: ?>
                    <tr>
                        <td colspan="4">No Related Cases</td>
                    </tr>
                    <?php endif; ?>
                <?php endforeach; ?>

我想通了。我只是将 if 语句放在 foreach 循环之外。咄!!它现在可以工作,但如果有人有更好的解决方案,请分享

最新更新