Tag Archives: json

Cakephp3: sending json response message to view

23666Method1:

Method2:

//controller action

 

Send Form data with ajax to cakephp controller

23666The following example shows how to submit a form with AJAX to a Cakephp controller;

Jquery Javascript Funtion;

CakePHP 3 Form:

 

Cakephp3 Ajax data submission example

23666How to create a javascript function to send a AJAX request to your cakePHP controller action;

 

 

Cakephp controller action;

 

How to add REST features to your Cakephp 3 App

23666To add REST features to your CakePHP 3 you simply need to add two lines of code to your controller;

This will allow any action in the controller to be viewed as JSON or XML .

To view your action index as JSON simply;

http://localhost/mycakeapp/mycontroller/index.json

Rest Examples:
http://localhost/mycakeapp/mycontroller/view/1.json

http://localhost/mycakeapp/mycontroller/view/1.xml

 

 

Then in routes.php file /config/routes.php add;

More info from the manual:
http://book.cakephp.org/3.0/en/development/routing.html#resource-routes

Cakephp Tip #3 – Requesting JSON or XML

The newest version of Cakephp makes it even easier to make a JSON or XML request.

Add the request handler component to your controller;

create your action in your controller;
eg

To access either the JSON or XML version simply append .json or .xml to the action name;

http://localhost/myapp/posts/testjson.json

http://localhost/myapp/posts/testjson.xml

Manual: