Using same route for different controllers?

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kdim95
Advanced
Posts: 207
Joined: 26 Aug 2022, 12:17

Using same route for different controllers?

Post by kdim95 » 29 Jun 2023, 15:05

Laravel framework version: 10.13.5
Aimeos Laravel version: ~2023.04
PHP Version: 8.2.7
Environment: Linux

Hello,

I want my CMS pages route and Products route to be the same.

It needs to accept any URL, check if the CMS page route exists, if it doesn't exist, redirect to the Products route.

That's why I have my routes in this order:

Code: Select all

// CMS Page
Route::match( ['GET', 'POST'], '{path?}', [
	'as' => 'my_page',
	'uses' => '\Aimeos\Shop\Controller\PageController@indexAction',
])->where([
	'path' => '.*'
]);

// Product listing
Route::match( ['GET', 'POST'], '{f_name?}', array(
	'as' => 'my_shop_tree',
	'uses' => 'Aimeos\Shop\Controller\CatalogController@treeAction'
))->where([
	'locale' => '[a-z]{2}(\_[A-Z]{2})?',
	'site' => '[A-Za-z0-9\.\-]+',
	'f_name' => '.*'
]);
I'm planning to override this file and make changes for the body() method.
Aimeos\Client\Html\Cms\Page::body()

Inside this check on row 179:

Code: Select all

if( !isset( $view->pageCmsItem ) ) {
// Redirect to to product listing (my_shop_tree) Aimeos\Shop\Controller\CatalogController@treeAction
}
Problem is that I don't know how I can redirect to the product listing controller and pass the initial path that was passed to the CMS page to it.

How can I achieve this?
Last edited by kdim95 on 30 Jun 2023, 14:05, edited 1 time in total.

User avatar
aimeos
Administrator
Posts: 7907
Joined: 01 Jan 1970, 00:00

Re: Using same route for different controllers?

Post by aimeos » 30 Jun 2023, 07:56

The same route can't be matched by different controllers, the first one will always win.
If you add the catalog list and cms page components to the same page, the catalog controller will handle the route and the cms page component will match to the URL path (not the route). Then, add a cms page with the same URL path in the CMS panel of the admin backend.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply