CakePHP 3.x: all routes to the plugin -


this not real question, need confirmation know if understand i'm studying (the routes of cakephp).

i have plugin myplugin. default, requests should directed plugin, wish plugin name doesn't appear in url.

for example:

/pages 

should resolved as:

['controller' => 'pages', 'action' => 'index', 'plugin' => 'myplugin'] 

the same should apply "admin" prefix.

for example:

/admin/pages 

should resolved as:

['controller' => 'pages', 'action' => 'index', 'plugin' => 'myplugin', 'prefix' => 'admin'] 

in short, have imagine if application (so except myplugin) has no controller.

i studied routes (particularly this , this) , know if code correct:

router::defaultrouteclass('inflectedroute');  router::prefix('admin', function ($routes) {     $routes->plugin('mecms', ['path' => '/'], function ($routes) {         $routes->fallbacks();     }); });  router::scope('/', ['plugin' => 'mecms'], function ($routes) {       $routes->fallbacks(); }); 

from tests, seems work. since routes have changed lot compared cakephp 2.x, have confirmation have understood.

thanks.


edit

thanks pgbi, code should final:

router::scope('/', ['plugin' => 'mecms'], function ($routes) {     router::connect('/admin', ['controller' => 'pages', 'action' => 'index', 'plugin' => 'mecms', 'prefix' => 'admin']);      $routes->prefix('admin', function ($routes) {         $routes->fallbacks();     });     $routes->fallbacks(); }); 

yes that's correct. think shorter (to tested, idea):

router::scope('/', ['plugin' => 'mecms'], function ($routes) {       $routes->prefix('admin', function ($routes) {         $routes->fallbacks();     });     $routes->fallbacks(); }); 

edit: add homepage admin section :

router::scope('/', ['plugin' => 'mecms'], function ($routes) {       $routes->prefix('admin', function ($routes) {         $routes->connect('/', ['controller' => 'pages', 'action' => 'index']);         $routes->fallbacks();     });     $routes->fallbacks(); }); 

you don't need repeat ['plugin' => 'mecms'] or ["prefix" => "admin"] since it's defined before.


Comments

Popular posts from this blog

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -

html - grunt SVG to webfont -