Commit 76eeca54 authored by duke's avatar duke

Разработать API для страницы "Конфигураторы оборудования"

parent 0937cc34
......@@ -164,6 +164,9 @@ return [
'class' => 'yii\rest\UrlRule',
'controller' => 'api/static',
'pluralize' => false,
'tokens' => [
'{id}' => '<id:.+>',
],
'only' => ['view', 'options']
],
[
......
<?php
namespace frontend\modules\api\components;
use yii\db\ActiveRecordInterface;
use yii\rest\Action;
use yii\web\NotFoundHttpException;
/**
* Class PageAction
* @package frontend\modules\api\components
*/
class PageAction extends Action
{
/**
* Displays a model.
* @param string $id the primary key of the model.
* @return \yii\db\ActiveRecordInterface the model being displayed
*/
public function run($id)
{
$model = $this->findModel($id);
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id, $model);
}
return $model;
}
public function findModel($id)
{
/* @var $modelClass ActiveRecordInterface */
$modelClass = $this->modelClass;
$model = $modelClass::find()
->where(['url' => $id])
->limit(1)
->one();
if (isset($model)) {
return $model;
}
throw new NotFoundHttpException("Object not found: $id");
}
}
\ No newline at end of file
......@@ -3,8 +3,8 @@
namespace frontend\modules\api\controllers;
use common\modules\content\models\CoContent;
use frontend\modules\api\components\PageAction;
use yii\rest\Controller;
use yii\rest\ViewAction;
/**
* Class StaticController
......@@ -29,7 +29,7 @@ class StaticController extends Controller
{
return [
'view' => [
'class' => ViewAction::className(),
'class' => PageAction::className(),
'modelClass' => CoContent::className()
]
];
......
......@@ -2,9 +2,9 @@
Используется для получения контента страницы API.
**URL** : `/api/static/{id}`
**URL** : `/api/static/{slug}`
`{id}` - идентификатор страницы, можно узнать в ПУ http://taskon.task-on.com/content/content-admin/manage
`{slug}` - url страницы, можно узнать в ПУ http://taskon.task-on.com/content/content-admin/manage
**Method** : `GET`
......@@ -12,7 +12,7 @@
**Data example**
`/api/static/9`
`/api/static/for-api`
## Success Response
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment