Customizing Strapi: Creating Controllers

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024
  • Description:
    In this video, we show you how you can create three different types of actions on a custom controller in Strapi. First, we create a completely custom action, second, we override an action using built-in functionality, and finally, we override an action using more custom functionality. Creating different types of actions on a controller allows you to fully customize the CRUD operations offered out of the box by Strapi.
    Chapters:
    0:19 - CMS Collection Setup
    2:50 - Create Custom Controller Action
    4:42 - Create Custom Route
    6:33 - Wrap Existing Controller Action
    9:19 - Advanced Override of Controller Action
    ---
    Follow the Quick Start Guide: docs.strapi.io....
    Try live demo: strapi.io/demo
    Strapi Blog: strapi.io/blog
    Find help in our Forum: forum.strapi.io/
    We are hiring! strapi.io/careers

Комментарии • 19

  • @unoleeone
    @unoleeone 2 года назад +8

    Great, also expecting Custom GraphQL, please

  • @ArtOfFun
    @ArtOfFun 2 года назад

    Thank you for this tutorial. That's what I was looking for!

  • @cristianocolangelo9920
    @cristianocolangelo9920 2 года назад +6

    Would be cool to get some more content on how to extend GraphQL endpoints

  • @jsricochet
    @jsricochet Год назад

    Clear and to the point. Thanks :)

  • @dmitryzhuravlev-nevsky1388
    @dmitryzhuravlev-nevsky1388 Год назад +1

    Thank you. It doesn't seem as a brand new Strapi setup tho. The GET /api/todos responses with 403 Forbidden. Can you clarify this step, please?

  • @moneyfr
    @moneyfr 2 года назад +8

    Sound too low

  • @nicom2009
    @nicom2009 Год назад

    Thanks

  • @user-zw6ff2us5l
    @user-zw6ff2us5l Год назад +1

    I want create custom routes and controller without content type in Typescript so please provide the details.

  • @ezequielviera7048
    @ezequielviera7048 9 месяцев назад +1

    Does this solution still work?
    because I tried to follow the steps and when I try to access the ctx.body (as well as its parameters) I get this error: "The property 'body' does not exist in type 'unknown'.ts(2339)".
    my project is js, but maybe from the year in which this video was published to the current date there have been changes.

    • @Strapi
      @Strapi  9 месяцев назад +1

      Can you share a code snippet or example? Here is another example of a plugin I was working on where I created custom controllers github.com/PaulBratslavsky/strapi-plugin-open-ai-embeddings/blob/main/server/controllers/open-ai-embeddings.js. that call custom service.
      We also have an open office house Monday - Friday at 12:30 PM CST if you want to stop by and share your example. discord.com/invite/strapi

    • @ezequielviera7048
      @ezequielviera7048 9 месяцев назад

      @@Strapi Of course, thanks for replying and sharing an example.
      in my consultation.js controller I have the following code:
      'use strict';
      const { createCoreController } = require('@strapi/strapi').factories;
      module.exports = createCoreController('api::consultation.consultation', ({ strapi }) => ({
      async exampleAction(ctx) {
      try {
      ctx.request.body; // Property 'body' does not exist in type 'Request'.ts(2339) any
      ctx.body.exampleParameter; //Property 'exampleParameter' does not exist in type 'unknown'.ts(2339) any
      } catch (err) {
      ctx.body = err;
      }
      }
      }));
      I've tried several ways but I get the error you see commented out, that it can't access properties of an unknown type.
      To try to solve this problem, and as I had already created custom endpoints in extensions/users-permissions/strapi-server.js, I decided to develop my endpoint there. Certainly I think it is not the right place, but adding it to the pulgin did not bring me these inconveniences:
      plugin.controllers.user.exampleAction= async (ctx) => {
      try {
      ctx.request.body; // no problems
      ctx.request.body.exampleParameter; // no problems
      } catch (err) {
      ctx.response.body = err;
      }
      }

    • @soutrikbanerjee8243
      @soutrikbanerjee8243 5 месяцев назад

      i was trying to get the parameter by const { query }=ctx.params and then strapi.query('api::partner.partner').findMany({ query }) it is not working when i tried to console.log i got undefined

  • @jhon73120
    @jhon73120 Год назад +1

    please, update your documentation in the website, do some more examples

  • @--VICKY-
    @--VICKY- Год назад

    is there any way to get data from api by filtering data present in components?

  • @edwardalmanzar8382
    @edwardalmanzar8382 2 года назад +1

    👍

  • @jsricochet
    @jsricochet Год назад

    Thank to your video, I was able to create a custom action to list all the options of an enum named 'originality'. It works fine. But I was wondering if this Is the recommended way to do so or if there is an easier way to list all possible values of an enum belonging to a model (here, the 'idea' model)? My aim is to populate a drop list used by a React client without having to hard code the options clientside so that if an extra option is added, it is reflected clientside.
    async getOriginality(ctx) {
    const model = strapi.getModel("api::idea.idea");
    const originality = model.attributes.originality.enum;
    return { originality };
    },

  • @khaledsanny4817
    @khaledsanny4817 Год назад

    Who are you talking to ? The content itself is great ...but its so difficult to hear you ...its not cool.... adress that plz