File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -371,6 +371,15 @@ public function findOne($condition = '', $params = array())
371371 return $ arr [0 ];
372372 }
373373
374+ public function findOneOrFail ($ condition = '' , $ params = array ())
375+ {
376+ $ data = static ::findOne ($ condition , $ params );
377+ if ($ data == null ) {
378+ throw new NotFoundException ('Data not found ' );
379+ }
380+ return $ data ;
381+ }
382+
374383 /**
375384 * 根据主键查询, 没有结果时返回null
376385 *
@@ -398,7 +407,7 @@ public function findByPkOrFail($id, $primaryKeyField = null)
398407 {
399408 $ data = static ::findByPk ($ id , $ primaryKeyField );
400409 if ($ data == null ) {
401- throw new NotFoundException (" Data not found: # " . $ id );
410+ throw new NotFoundException (' Data not found: # ' . $ id );
402411 }
403412 return $ data ;
404413 }
You can’t perform that action at this time.
0 commit comments