ViewAction.php 887 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * @link https://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license https://www.yiiframework.com/license/
  6. */
  7. namespace yii\rest;
  8. /**
  9. * ViewAction implements the API endpoint for returning the detailed information about a model.
  10. *
  11. * For more details and usage information on ViewAction, see the [guide article on rest controllers](guide:rest-controllers).
  12. *
  13. * @author Qiang Xue <qiang.xue@gmail.com>
  14. * @since 2.0
  15. */
  16. class ViewAction extends Action
  17. {
  18. /**
  19. * Displays a model.
  20. * @param string $id the primary key of the model.
  21. * @return \yii\db\ActiveRecordInterface the model being displayed
  22. */
  23. public function run($id)
  24. {
  25. $model = $this->findModel($id);
  26. if ($this->checkAccess) {
  27. call_user_func($this->checkAccess, $this->id, $model);
  28. }
  29. return $model;
  30. }
  31. }