ViewAction.php 895 B

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