I have cakephp4 project
implemented i18n internationalization, it is working with session.
but I want the language parameter in URL as below
mydomain/en/controllers/action
mydomain/ar/controllers/action
and also for Admin prefix
mydomain/en/admin/controllers/action
mydomain/en/admin/controllers/action
I able to do it without Admin prefix but Language parameter along with Admin prefix is not working
tried many things my current routes.php is as below
<?php
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder) {
$builder->connect('/', ['controller' => 'cv', 'action' => 'index']);
$builder->connect('/:language/:controller/:action/*', array(), array('language' => 'en|ar'));
$builder->connect('/:language/:controller', array('action' => 'index'), array('language' => 'en|ar'));
$builder->connect('/:language', array('controller' => 'cv', 'action' => 'index'), array('language' => 'en|ar')) ;
$builder->fallbacks();
});
$routes->prefix('Admin', function (RouteBuilder $routes) {
$routes->connect('/:language', array('controller' => 'Users', 'action' => 'login'), array('language' => 'en|ar')) ;
$routes->connect('/:language/:controller', array('action' => 'index'), array('language' => 'en|ar'));
$routes->connect('/:language/:controller/:action/*', array(), array('language' => 'en|ar'));
$routes->connect('/', ['controller' => 'Users', 'action' => 'login']);
//$routes->connect('/:language', array('controller' => 'Users', 'action' => 'login'), array('language' => 'en|ar')) ;
$routes->fallbacks(DashedRoute::class);
});
//below also not working
// $routes->scope('/:language', function (RouteBuilder $routes) {
// $routes->prefix('Admin', function (RouteBuilder $routes) {
// $patterns = ['language' => 'en|ar'];
// $routes
// ->connect('/:controller/:action/*', [])
// ->setPatterns($patterns);
// $routes
// ->connect('/:controller', ['action' => 'index'])
// ->setPatterns($patterns);
// $routes
// ->connect('/', ['controller' => 'Users', 'action' => 'login'])
// ->setPatterns($patterns);
// });
// });
mydomain/en/admin/controllers/action says: AdminController could not be found.