routing - Cakephp 3 : Plugin’s rooting in a prefix -
i have problem routing. have plugin can not connect route in prefix.
plugins url : /plugin-name/test : call testcontroller in "pluginsname/testcontroller.php"
i wan't /myprefix/plugin-name/test : call testcontroller in "pluginsname/testcontroller.php
my differents test :
<?php router::prefix('myprefix', function ($routes) { // call testcontroller in plugin in "pluginsname/api/testcontroller.php" $routes->connect('/plugin-name/test', ['plugin' => 'pluginname', 'controller' => 'test', 'action' => 'display']); // error $routes->connect('/plugin-name/test', ['plugin' => 'pluginname', 'controller' => 'test', 'action' => 'display', 'prefix'=>false]); not work $routes->plugin('pluginname', function($routes) { $routes->connect('/test', ['controller' => 'test', 'action' => 'display']); }); });
do have solution ?
try this. should work.
router::plugin('contacts', ['_nameprefix' => 'contacts:'], function ($routes) { $routes->scope('/api', ['_nameprefix' => 'api:'], function ($routes) { // route's name `contacts:api:ping` $routes->connect('/ping', ['controller' => 'pings'], ['_name' => 'ping']); }); });
it make, url /contacts/api/ping
redirect contacts plugin pings controller.
for example:
router::plugin('contacts', ['_nameprefix' => 'contacts:'], function ($routes) { // route's name `contacts:ping` $routes->connect('/ping', ['controller' => 'pings'], ['_name' => 'ping']); });
it redirect contact plugin , pings controller /contacts/ping
.
Comments
Post a Comment