question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi I try to personalize the post in an action but it asks me an id?

namespace AppBundle\Action;

use AppBundle\Entity\Book;
use Doctrine\Common\Persistence\ManagerRegistry;
use GuzzleHttp\Psr7\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;

class BookSpecial
{
    private $myService;
    /**
     * @var Container
     */
    private $container;

    public function __construct(MyService $myService,Container $container, AuthorizationChecker $checker)
    {
        $this->myService = $myService;
        $this->container = $container;
        $this->authorizationChecker = $checker;
    }

    /**
     * @Route(
     *     name="book_special",
     *     path="api/books/special",
     *     defaults={"_api_resource_class"=Book::class, "_api_item_operation_name"="special"},
     *     options={"i18n" = false }
     * )
     * @Method("POST")
     */
    public function __invoke($data)
    {

        if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
            $data =  array('error'=>410);
            return new JsonResponse($data, 400);
    }
        $this->myService->doSomething($data);


        return $data; // API Platform will automatically validate, persist (if you use Doctrine) and serialize an entity
        // for you. If you prefer to do it yourself, return an instance of Symfony\Component\HttpFoundation\Response
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
oxnel88commented, Jan 21, 2017

@nlefebvre1410 try changing the parameter of the route defaults key to: “_api_collection_operation_name”

0reactions
julestruongcommented, Aug 4, 2017

@oxnel88 THANK YOU

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create Custom Post Types in WordPress - WPBeginner
Another easy way to create a custom post type in WordPress is by using a plugin. This method is recommended for beginners because...
Read more >
Custom Post Type UI – WordPress plugin
Custom Post Type UI provides an easy to use interface for registering and managing custom post types and taxonomies for your website.
Read more >
The Complete Guide To WordPress Custom Post Types
A custom post type is nothing more than a regular post with a different post_type value in the database. The post type of...
Read more >
How to Create Custom Post Type in WordPress (Easy Guide)
Click the registered custom post type, which in our case is “News.” · Click Add New. · Type the title and body of...
Read more >
WordPress Custom Post Types: The All-In-One Guide ... - Kinsta
Another custom content type you have in WordPress is custom fields, also known as post metadata. Custom fields are additional metadata you can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found