aminkt / yii2-category-module
分类模块
1.0.0
2018-09-21 10:10 UTC
Requires
- aminkt/yii2-alert-widget: dev-master
- aminkt/yii2-custom-exceptions: dev-master
- aminkt/yii2-input-tag-widget: dev-master
- aminkt/yii2-tree-view-widget: dev-master
- kartik-v/yii2-widget-select2: @dev
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-09-06 04:14:56 UTC
README
分类模块
安装
安装此扩展的首选方式是通过 composer。
运行以下命令
php composer.phar require --prefer-dist saghar/yii2-category-module "v1.1.0.x-dev"
或者
"saghar/yii2-category-module": "v1.1.0.x-dev"
将以下内容添加到你的 composer.json
文件的 require 部分中。
配置
扩展安装完成后,只需在你的代码中使用它即可
- 在模块部分将模块配置添加到你的配置文件中,如下所示
'category' => [ 'class' => \saghar\category\Category::class, 'modelClass' => \path\to\your\Model::class, 'searchModelClass' => \path\to\your\search\Model::class ],
注意:你可以留空
modelClass
和searchModelClass
以使用模块的默认模型。如果你正在使用 mongo db,你可以使用在\saghar\category\models\mongo
中实现的模型。
- 使用
yii migrate --migrationPath=@vendor/saghar/yii2-category-module/src/migrations --interactive=0
运行模块的迁移文件
注意:如果你正在使用 mongo db,请跳过此步骤。
高级配置
如果你想使用自己的模型,请随意编写自己的代码,但请注意这些步骤以使用分类模块配置你的应用程序。
-
创建自己的 Active Record 并实现
\saghar\category\interfaces\CategoryInterface
-
在配置文件中定义你的模型,如配置部分所述。
完成。
使用分类模块 API 创建、更新、删除和获取你的分类。
你可以使用 \saghar\category\controllers\RestApiController
并从该文件扩展你的控制器。该文件将提供以下动作和路由
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.
注意:除 index 和 view 之外的所有请求都应至少使用一个认证方法进行认证。
警告:默认情况下禁用了跨源。如果你遇到任何与此相关的问题,请报告。