cakephp 3.x routing to subfolders -
on website have usual routes for
website.com website.com/pages/about website.com/img/116633 ... now have these pages
website.com/username/mike website.com/username/john website.com/username/eric ... which should become
website.com/mike website.com/john website.com/eric ... my routing goes this:
$routes->connect( '/*', ['controller' => 'username', 'action' => 'index'], ['routeclass' => 'dashedroute'] ); and works, other pages like
website.com/pages/about website.com/img/116633 are broken (they take 'controller' => 'username')
what best way make happen?
below full routes.php
router::defaultrouteclass('route'); router::extensions(['html', 'rss', 'pdf']); router::scope('/', function ($routes) { $routes->connect('/', ['controller' => 'search', 'action' => 'start']); $routes->connect('/start', ['controller' => 'search', 'action' => 'start']); $routes->connect( '/*', ['controller' => 'username', 'action' => 'index'], ['routeclass' => 'dashedroute'] ); $routes->fallbacks('inflectedroute'); }); router::connect('/img/*', ['controller' => 'pic', 'action' => 'item']); router::url([ 'controller' => 'pages', 'action' => 'lang', '_base' => 'false' ]); router::addurlfilter(function ($params, $request) { if (isset($request->params['lang']) && !isset($params['lang'])) { $params['lang'] = $request->params['lang']; } return $params; }); plugin::routes();
$routes->connect( '/*', ['controller' => 'username', 'action' => 'index'], ['routeclass' => 'dashedroute'] ); has replaced with:
$routes->connect( '/:username', ['controller' => 'username', 'action' => 'index'], [ 'pass' => ['username'], 'username' => '[0-9a-za-z]+' ] ); this passes username url index() in username controller.
for more information: route elements , passing parameters action.
Comments
Post a Comment