Skip to content

Instantly share code, notes, and snippets.

@gentunian
Last active August 29, 2015 14:16
Show Gist options
  • Save gentunian/54a27abc4b3d54706c4e to your computer and use it in GitHub Desktop.
Save gentunian/54a27abc4b3d54706c4e to your computer and use it in GitHub Desktop.
Testing REST cakephp3
2015-03-11 16:27:16 Error: [Cake\Controller\Exception\MissingActionException] Action RecipesController::index.json() could not be found, or is not accessible.
Exception Attributes: array (
'controller' => 'RecipesController',
'action' => 'index.json',
'prefix' => '',
'plugin' => NULL,
)
<?php
namespace App\Controller;
use Cake\Controller\Controller;
class RecipesController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
}
public function index()
{
$recipes = [ '1' => 'one', '2' => 'two', '3' =>'three'];
$this->set([
'recipes' => $recipes,
'_serialize' => ['recipes']
]);
}
public function view($id)
{
$recipe = [ 'id' => $id];
$this->set([
'recipe' => $recipe,
'_serialize' => ['recipe']
]);
}
public function add()
{
$message = "added";
$this->set([
'message' => $message,
'_serialize' => ['message']
]);
}
public function edit($id)
{
$message = "edit";
$this->set([
'message' => $message,
'_serialize' => ['message']
]);
}
public function delete($id)
{
$message = "delete";
$this->set([
'message' => $message,
'_serialize' => ['message']
]);
}
}
<?php
use Cake\Core\Plugin;
use Cake\Routing\Router;
Router::defaultRouteClass('Route');
Router::scope('/', function ($routes) {
$routes->connect('/', array('controller' => 'Pages', 'action' => 'home'));
$routes->fallbacks('InflectedRoute');
$routes->extensions(['json']);
});
Router::scope('/guardia', function ($routes) { $routes->extensions(['json']);});
Router::scope('/jboss_stages', function ($routes) {
$routes->extensions(['json']);
});
Plugin::routes();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment