Localization of Blog plugin urls with admad/cakephp-i18n

Hi,

I working on a website wich use the admad/cakephp-i18n for translations, no problem with the regular controllers but impossible to get localized urls for a “Blog” plugin. I’m not the creator of this website, I just work know on it and I’m relatively new on CakePHP (but 20 years of PHP development).

I just declared the routeClass in the plugin routes declarations like it’s done in the main routes:

$routes->connect(
	'//:slug-:id.html',
	['controller' => 'Articles', 'action' => 'view'],
	['routeClass' => 'ADmad/I18n.I18nRoute', 'pass' => ['id', 'slug']]
);

and my urls are correctly constructed but when I try to access the page (like /fr/blog/test-85.html), it raise the following error:

[Cake\Routing\Exception\MissingControllerException] Controller class Blog could not be found.

I’m using CakePHP 3.6.15, admad/cakephp-i18n 1.2 and I don’t know where the Blog plugin comes from.

An idea allowing me to solve this problem?

Thx in advance for your help!
David

By convention, controller names are plural. Could it simple be that you are using singular ‘blog’?

Hi @dreamingmind, thx for your answer.

I don’t think the problem is with the “blog” pural.

My problem is that with the language in the url, the “Blog” controller is not found while without the language it works as expected.

Without 'routeClass' => 'ADmad/I18n.I18nRoute', the url /blog/test-85.html work correctly, with the new route, the url /fr/blog/test-85.html is well constructed but crash when it try to load the page.

Here is the whole route for the plugin:

<?php
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\Routing\Route\DashedRoute;

$defaultRouting = function ($routes) {

	$routes->connect('/', ['action' => 'index']);

	$routes->connect(
		'//rss',
		['controller' => 'Articles', 'action' => 'rss'],
        ['routeClass' => 'ADmad/I18n.I18nRoute']
	);

	$routes->connect(
		'//sitemap',
		['controller' => 'Articles', 'action' => 'sitemap'],
        ['routeClass' => 'ADmad/I18n.I18nRoute']
	);

	$routes->connect(
		'//proposal',
		['controller' => 'Articles', 'action' => 'proposal'],
        ['routeClass' => 'ADmad/I18n.I18nRoute']
	);

	$routes->connect(
		'//:slug-:id.html',
		['controller' => 'Articles', 'action' => 'view'],
		['routeClass' => 'ADmad/I18n.I18nRoute', 'pass' => ['id', 'slug']]
	);

	$routes->connect(
		'//:slug',
		['controller' => 'Articles', 'action' => 'index'],
		['routeClass' => 'ADmad/I18n.I18nRoute', 'pass' => ['slug']]
	);

	$routes->connect('/:action/*');
};

Router::scope('/blog', ['plugin' => 'Blog', 'controller' => 'Articles'], $defaultRouting);

Router::plugin(
	'Blog',
	['path' => '/blog'],
	function (RouteBuilder $routes) {	
		$routes->fallbacks(DashedRoute::class);
	}
);

Router::prefix('admin', function($routes) {

	$routes->plugin('Blog', function ($routes) {
		$routes->fallbacks('InflectedRoute');
	});
});

I don’t know how to make this work, the same use of 'routeClass' => 'ADmad/I18n.I18nRoute' with a regular controller (not a plugin) gives a working url with the language at the begining (/fr/<controller>/<id> for example).

Any idea?