first commit
This commit is contained in:
33
frontend/controllers/CategoryController.php
Executable file
33
frontend/controllers/CategoryController.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
|
||||
|
||||
use common\models\Category;
|
||||
|
||||
/**
|
||||
* Product controller
|
||||
*/
|
||||
class CategoryController extends BaseApiController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
return Category::find()
|
||||
->select(['id', 'name'])
|
||||
->all();
|
||||
}
|
||||
|
||||
public function actionWithProducts()
|
||||
{
|
||||
return Category::find()
|
||||
->select(['id', 'name'])
|
||||
->with([
|
||||
'products' => function (\yii\db\ActiveQuery $query) {
|
||||
$query->select(['name', 'description', 'price', 'category_id']);
|
||||
}
|
||||
])
|
||||
->asArray()
|
||||
->all();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user