In CakePHP 2
I always used empty
to check if there any result.
<?php
$result = $this->Modelname->find('first', ['conditions' => ['field' => 'value'] ] );
if ( empty($result) ) {
// Bad Request
}
In CakePHP 3
it looks weird to me.
$fancyTable = TableRegistry::get('FancyTable');
$query = $fancyTable->find()->where(['name' => 'fancy', 'active' => 0]);
if ( 0 === $query->count() ) {
// Bad Request
}
Is this the right way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…