2
votes

I am making small project in cakePHP v3.5, i am not able to use parametrized in appropriate way. Also in some cases if we want to pass optional parameter in url then how can i do?

CakePHP v3.5

$routes->get('test/testfn/:param1/:param2', ['controller' => 'Pages', 'action' => 'testfn']);

where 
test: Controller,
testfn: Method of TestController,
param1: Parameter 1,
param2: Parameter 2

All i did to get params from url to TestController,

  $this->request->getParam(param1)
  $this->request->getParam(param2)

How can i list all parameters that i passed from routes to My Controller instead of single param step by step.

OR anyone have better options to do routing in cakePHP v3.5

Also I am confused about the paramterized routing principle of cakePHP3.4 so, in that case if anyone has some solution to cakePHP v3.4.

Please Help me.

Thanks

2
In cake 3.4 Routing with params :- stackoverflow.com/questions/37448765/…Aman Kumar
It's not clear what you're asking. Are you asking how to define routes or how to read route parameters.Reactgular
@cgTag can you just explain how can we do parameterized routing in cakePHP3.5. ThanksSanjay Kumar Singh

2 Answers

1
votes

In config/routes.php

$routes->get(
            '/api/test/*', ['controller' => 'Api', 'action' => 'check']
    );

In controller

public function check($first=null, $sec=null) {

   pr($params);
   pr($sec);
   die;
}
0
votes

In Routes.php

$routes->connect('/users/:id/edit/:type', ['controller' => 'Users', 'action' => 'edit', ['id' => '\d+', 'pass' => ['id', 'type'], '_name' => 'edit-client']);

In this route in ID is user id and Type is user type two parameter pass in this route

if this route method is POST then ex - $this->request->getData('id'); and if this route method GET then ex - $this->request->getParam('id')