custom POST
See original GitHub issueHi 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:
- Created 7 years ago
- Comments:12 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nlefebvre1410 try changing the parameter of the route defaults key to: “_api_collection_operation_name”
@oxnel88 THANK YOU