The Add
action (POST method) in CakePHP 3 is not working and it is asking fields that I already informed in json message. Let me explain:
mod_rewrite
activated;sakila
;Country
model from Bake;AppController
class content to load CRUD plugins changing it's content to:namespace App\Controller; use Cake\Controller\Controller; class AppController extends Controller { use \Crud\Controller\ControllerTrait; public $components = [ 'RequestHandler', 'Crud.Crud' => [ 'actions' => [ 'Crud.Index', 'Crud.View', 'Crud.Add', 'Crud.Edit', 'Crud.Delete' ], 'listeners' => [ 'Crud.Api', 'Crud.ApiPagination' ] ] ]; }
app/config/routes.php
;app/config/routes.php
;I'm using Postman for Chrome and setting header Accept
and Content-Type
value to application/json
and sending POST to following link: http://localhost:8080/mtag/country with the following json content:
{ "country": "BlaBlaBla", "last_update": "2015-12-24" }
But I receive the following status code: 412 Precondition Failed. In returned json:
success: false, data: { code: 412, message: "2 validation errors occured", }
The missing fields indicated is country
and last_update
but I informed them in json. What I did wrong? Did someone have an example how to use CakePHP CRUD correctly using json?
When I am using Postman for testing the cakePHP CRUD functions I do NOT use application/json
for Content-Type
but leave it blank. And for the body part just use form-data
instead of a json object while using a raw
body.