Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "products".
- *
- * @property int $id
- * @property string $name
- * @property int $supplier_id
- */
- class Product extends \yii\db\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'products';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['supplier_id'], 'integer'],
- [['name'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'name' => 'Name',
- 'supplier_id' => 'Supplier ID',
- ];
- }
- }
- Controller - ProductController
- <?php
- namespace app\Controllers;
- use app\models\Product;
- use yii\data\ActiveDataProvider;
- use yii\rest\ActiveController;
- class ProductController extends ActiveController
- {
- public $modelClass = 'app\models\Product';
- public $serializer = [
- 'class' => 'yii\rest\Serializer',
- 'collectionEnvelope' => 'items',
- ];
- public function actionIndex()
- {
- var_dump('here');
- }
- }
- and routes in url manager
- ...
- 'urlManager' => [
- 'enablePrettyUrl' => true,
- 'showScriptName' => false,
- 'enableStrictParsing' => true,
- 'rules' => [
- ['class' => 'yii\rest\UrlRule', 'controller' => 'product'],
- ],
- ],
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement