I'm trying to replace all of my static routes with the CakePHP 3.8 Router::url() method.
On my local environment, when accessing the the below code from the manage/lender-products/read/2 route, I get the expected results of /manage/lenders from the below code:
\Cake\Routing\Router::url(['controller' => 'Lenders', 'action' => 'index'])
However, on production (bref.sh/AWS Lambda/PHP 7.4), I get the unexpected result of /manage/lender-products/read/manage/lenders.
It appears that in my production environment, the URL is being generated and is including the current pages url in the end result.
In case you do not set a custom base path for the
App.baseconfig option, CakePHP will try to figure the possible base path out on its own, based on$_SERVER['PHP_SELF']and$_SERVER['DOCUMENT_ROOT'], so it's likely that one or both of these contain unexpected values in your AWS environment.The simple fix would be to manually set the base path in your
config/app.php. If your application doesn't actually live in a public subdirectory (ie in casewebrootis your document root), then you should set the path to an empty string, otherwise provide the path, like/my/app(with a leading slash, but without a trailing slash!).See also