-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
Description
When specifying a particular template from a controller as shown below, an error occurs.
$this->render('PluginName.PluginController/custom_file');
Error message:
ROOT/plugins/PluginName/templates/PluginController/PluginController/custom_file.php
It seems that this error is caused by a change in the template path resolution logic introduced in CakePHP 5.3.
The relevant code in CakePHP 5.3 is shown below:
https://github.com/cakephp/cakephp/blob/5.3.0/src/View/View.php#L1371-L1379
CakePHP 5.3
if (!str_contains($name, DIRECTORY_SEPARATOR) && $name !== '' && !str_starts_with($name, '.')) {
$name = $templatePath . $subDir . $this->_inflectTemplateFileName($name);
} elseif (str_contains($name, DIRECTORY_SEPARATOR)) {
if (str_starts_with($name, DIRECTORY_SEPARATOR) || $name[1] === ':') {
$name = trim($name, DIRECTORY_SEPARATOR);
} else {
$name = $templatePath . $subDir . $name;
}
}
As a test, I reverted the relevant part to the CakePHP 5.2 logic, and the issue no longer occurred.
CakePHP 5.2
if (!str_contains($name, DIRECTORY_SEPARATOR) && $name !== '' && !str_starts_with($name, '.')) {
$name = $templatePath . $subDir . $this->_inflectTemplateFileName($name);
} elseif (str_contains($name, DIRECTORY_SEPARATOR)) {
if (str_starts_with($name, DIRECTORY_SEPARATOR) || $name[1] === ':') {
$name = trim($name, DIRECTORY_SEPARATOR);
} elseif (!$plugin || $this->templatePath !== $this->name) {
$name = $templatePath . $subDir . $name;
} else {
$name = $subDir . $name;
}
}
Could you please review this behavior?
Thank you for your time and consideration.
CakePHP Version
5.3.0
PHP Version
8.3