gpt4 book ai didi

strapi - 如何覆盖 Strapi 管理面板端点?

转载 作者:行者123 更新时间:2023-12-04 01:22:42 25 4
gpt4 key购买 nike

在管理面板中 - 我有一个内容类型 products ,它向我展示了数据库(MongoDB)中的所有产品

enter image description here

假设我想编辑一个 product当我点击 Save按钮,我想点击自定义 API/覆盖更新我的现有端点products收藏!

enter image description here

是否可以自定义或覆盖管理面板 API?

最佳答案

Strapi 管理员(strapi-admin)和内容管理器(strapi-plugin-content-manager)是分开定义的。
如果您想覆盖/扩展端点;通过定义要覆盖的函数来实现,如下所示:
在以下位置找到 Controller :

extensions/<plugin-name>/controllers/<controller-to-override-name>.js


例子:

extensions/content-manager/controllers/ContentManager.js


请注意,名称的“strapi-plugin”部分已删除!
如何在 Controller 文件中覆盖和扩展的示例:
'use strict';
module.exports = {

//this is how you destroy count
async count(ctx) {
ctx.body = {
count: 99
};
},
//this is how you extend
async aFuncThatDoesntExistInOriginalController(ctx) {
//add logic
},
};
如果您要扩展,则必须添加从路由到 Controller 和方法的映射
要查看哪个端点映射到 Controller 中的哪个方法,请查看:

node_modules/<plugin-name>/config/routes.json
node_modules/strapi-plugin-content-manager/config/routes.json


文档中的一些基本信息: controllers , customization1 & customization2FAQ

关于strapi - 如何覆盖 Strapi 管理面板端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62387941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com