php - view($id) Method is being called instead of index() Method with GET VERB [CakePHP] -
when enter url http://localhost/cake2/cruds verb method view() loads. want load index() method... when enter url http://localhost/cake2/cruds/8 verb same happens. remaining routes works fine.
my routes are:
router::connect('/', array('[method]'=>'get','controller' => 'cruds', 'action' => 'index')); router::connect('/', array('[method]'=>'post','controller' => 'cruds', 'action' => 'add')); router::connect('/:id', array('[method]'=>'get','controller' => 'cruds', 'action' => 'view','id')); router::connect('/:id', array('[method]'=>'put','controller' => 'cruds', 'action' => 'edit','id')); router::connect('/:id', array('[method]'=>'delete','controller' => 'cruds', 'action' => 'delete','id'));
same routes works fine in cakephp v3. controller methods are:
function index() { $this->loadmodel("crud"); $users = $this->crud->find('all'); //var_dump($users); $users = set::extract($users, '{n}.crud'); $this->set('message', json_encode($users,json_pretty_print)); }` `function view($id) { $this->loadmodel("crud"); $user = $this->crud->findbyid($id); if (!$user) { $this->set('message', "user not found..!"); } else { $this->set('message',json_encode($user['crud'],json_pretty_print)); } }
this line says call view
action on id
router::connect('/:id', array('[method]'=>'get','controller' => 'cruds', 'action' => 'view','id'));
so want call index added index instead of view
router::connect('/:id', array('[method]'=>'get','controller' => 'cruds', 'action' => 'index','id'));
(& dont know cake php)
Comments
Post a Comment