findModel() public method

If the data model is not found, a 404 HTTP exception will be raised.
public findModel ( string $id ) : yii\db\ActiveRecordInterface
$id string the ID of the model to be loaded. If the model has a composite primary key, the ID must be a string of the primary key values separated by commas. The order of the primary key values should follow that returned by the `primaryKey()` method of the model.
return yii\db\ActiveRecordInterface the model found
Beispiel #1
0
 public function findModel($id = null)
 {
     if (is_null($id)) {
         $modelClass = $this->modelClass;
         $emptyPrimaryKey = array_flip($modelClass::primaryKey());
         $primaryKey = array_merge($emptyPrimaryKey, array_intersect_key(Yii::$app->getRequest()->getQueryParams(), $emptyPrimaryKey));
         $id = implode(',', array_values($primaryKey));
     }
     return parent::findModel($id);
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function findModel($id)
 {
     $id = Uuid::str2uuid($id);
     return parent::findModel($id);
 }