I am new in cakephp,
I am trying to develop a simple REST BREAD (BROWSE, READ, EDIT, ADD, DELETE) using cakephp version 4.
After installed I created a simple controller called UsersController with method index,view,edit,delete
. Not created any model and templates yet.
For Browse json, in Users/index method I have used code like
public function index()
{
$users = $this->Users->find('all');
echo json_encode($users);
exit;
}
Output :
[
{
"id": 1,
"username": "jone",
"created": "2020-01-22T00:00:00+00:00",
"modified": "2020-01-22T00:00:00+00:00"
}
]
Questions :
1) Without using exit how I will prevent controller to render not found template error exception
?
2) How I will change http response code using cake asset. example 200 ok will be 2000 ok.
?
3) Without use json_encode , am I able to return a json view using cakephp asset, if yes then how ?