cakephp difference between Router::scope and Router::prefix -


i know router's prefix method adds prefix routes still confused scope method routes.is alias prefix or has own use.

router::prefix('api', function ($routes) {         $routes->scope('/v1', function ($routes) {                         $routes->connect('/', ['action'=>'index']);                $routes->connect('/:id', ['action'=>'view', ':id']);          });  });   

both allow sharing of common path segments. difference prefix controller within sub-namespace.

from documentation:

prefixes mapped sub-namespaces in application’s controller namespace ... using our users example, accessing url /admin/users/edit/5 call edit() method of our src/controller/admin/userscontroller.php passing 5 first parameter. view file used src/template/admin/users/edit.ctp

in above case, scope controller @ src/controller/userscontroller.php.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -