The preferred way to install this extension is through composer.
php composer.phar require --prefer-dist saghar/yii2-category-module "v1.1.0.x-dev"
to the require section of your
Once the extension is installed, simply use it in your code by :
- Add module configuration to your config file in module section like as:
'category' => [ 'class' => \saghar\category\Category::class, 'modelClass' => \path\to\your\Model::class, 'searchModelClass' => \path\to\your\search\Model::class ],
Note: You can leave
searchModelClassblank to use default models of module. If you are using mongo db, you can use models implemented in
- Run migration files of module using
yii migrate --migrationPath=@vendor/saghar/yii2-category-module/src/migrations --interactive=0
Note: If you are using mongo db please skip this step.
If you want use your own model feel free to write your own code but please be aware about this steps to configurate your your app using Category module.
Create your own Active record and implement
In you configuration file define your models like described in configuration section.
You can use
\saghar\category\controllers\RestApiController and extend your controller from this file.
This file will provide below actions and routes:
GET /v2/category // List of all categories. GET /v2/category/[id] // Detail of one single category. DELETE /v2/category/[id] // Delete a single category from server. POST /v2/category // Create a new category. PUT /v2/category/[id] // Update category.
Note: All request except index and view shoud use at least one auth method to authrize user.
Warning: Cross origin is disabled by default. if you have any problem with this please report it.