路由的自定义方面未按预期工作
Custom aspect for routing not working as expected
我已经编写了一个自定义方面,它应该只返回它得到的内容。这部分工作:
工作
?tx_myvender_users[action]=list&tx_myvender_users[company]=Company 1&tx_myvender_users[controller]=FrontendUser&tx_myvender_users[department]=SelectedDepartment&cHash=5413de3c7ca7efda6da4e9bb3a918945
转换为
company-1/department/SelectedDepartment/
不支持分页
?tx_myvender_users[%40widget_0][currentPage]=2&tx_myvender_users[action]=list&tx_myvender_users[company]=Company 1&tx_myvender_users[controller]=FrontendUser&tx_myvender_users[department]=SelectedDepartment&cHash=e8196678ef65f1c4d5423b617505f840
转换为
company-1/department/SelectedDepartment/2/
但它通过了 SelectedDepartment/2/
作为参数 department
,我不明白为什么。我希望 SelectedDepartment
用于 department
和 2
用于参数 @widget_0/currentPage
.
这是我在 config.yaml
中的路由配置:
routes: { }
routeEnhancers:
PageTypeSuffix:
type: PageType
default: /
index: ''
map:
/: 0
FeusersPlugin:
type: Extbase
extension: MyVendor
plugin: Users
limitToPages: [3]
defaultController: 'FrontendUser::list'
requirements:
company_page: '\d+'
routes:
- routePath: '{company_title}/department/{department_title}'
_controller: 'FrontendUser::list'
_arguments:
company_title: 'company'
department_title: 'department'
- routePath: '{company_title}/department/{department_title}/{company_page}'
_controller: 'FrontendUser::list'
_arguments:
company_title: 'company'
department_title: 'department'
company_page: '@widget_0/currentPage'
aspects:
company_title:
type: StaticValueMapper
map:
company-1: 'Company 1'
company-2: 'Company 2'
department_title:
type: DepartmentStaticMapper
company_page:
type: StaticRangeMapper
start: '1'
end: '100'
这是我的DepartmentStaticMapper
,它正在传回它得到的东西:
namespace MyVendor\Extension\Routing\Aspect;
use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
class DepartmentStaticMapper implements StaticMappableAspectInterface
{
protected $settings;
public function __construct(array $settings)
{
$this->settings = $settings;
}
public function generate(string $value): ?string
{
return $value;
}
public function resolve(string $value): ?string
{
return $value;
}
}
将 class DepartmentStaticMapper
更改为以下内容,解决了我的问题。我刚刚在 public function resolve(string $value)
:
中添加了斜线检查
namespace MyVendor\Extension\Routing\Aspect;
use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
class DepartmentStaticMapper implements StaticMappableAspectInterface
{
protected $settings;
public function __construct(array $settings)
{
$this->settings = $settings;
}
public function generate(string $value): ?string
{
return $value;
}
public function resolve(string $value): ?string
{
return strstr($value, '/') ? null : $value;
}
}
我已经编写了一个自定义方面,它应该只返回它得到的内容。这部分工作:
工作
?tx_myvender_users[action]=list&tx_myvender_users[company]=Company 1&tx_myvender_users[controller]=FrontendUser&tx_myvender_users[department]=SelectedDepartment&cHash=5413de3c7ca7efda6da4e9bb3a918945
转换为
company-1/department/SelectedDepartment/
不支持分页
?tx_myvender_users[%40widget_0][currentPage]=2&tx_myvender_users[action]=list&tx_myvender_users[company]=Company 1&tx_myvender_users[controller]=FrontendUser&tx_myvender_users[department]=SelectedDepartment&cHash=e8196678ef65f1c4d5423b617505f840
转换为
company-1/department/SelectedDepartment/2/
但它通过了 SelectedDepartment/2/
作为参数 department
,我不明白为什么。我希望 SelectedDepartment
用于 department
和 2
用于参数 @widget_0/currentPage
.
这是我在 config.yaml
中的路由配置:
routes: { }
routeEnhancers:
PageTypeSuffix:
type: PageType
default: /
index: ''
map:
/: 0
FeusersPlugin:
type: Extbase
extension: MyVendor
plugin: Users
limitToPages: [3]
defaultController: 'FrontendUser::list'
requirements:
company_page: '\d+'
routes:
- routePath: '{company_title}/department/{department_title}'
_controller: 'FrontendUser::list'
_arguments:
company_title: 'company'
department_title: 'department'
- routePath: '{company_title}/department/{department_title}/{company_page}'
_controller: 'FrontendUser::list'
_arguments:
company_title: 'company'
department_title: 'department'
company_page: '@widget_0/currentPage'
aspects:
company_title:
type: StaticValueMapper
map:
company-1: 'Company 1'
company-2: 'Company 2'
department_title:
type: DepartmentStaticMapper
company_page:
type: StaticRangeMapper
start: '1'
end: '100'
这是我的DepartmentStaticMapper
,它正在传回它得到的东西:
namespace MyVendor\Extension\Routing\Aspect;
use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
class DepartmentStaticMapper implements StaticMappableAspectInterface
{
protected $settings;
public function __construct(array $settings)
{
$this->settings = $settings;
}
public function generate(string $value): ?string
{
return $value;
}
public function resolve(string $value): ?string
{
return $value;
}
}
将 class DepartmentStaticMapper
更改为以下内容,解决了我的问题。我刚刚在 public function resolve(string $value)
:
namespace MyVendor\Extension\Routing\Aspect;
use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
class DepartmentStaticMapper implements StaticMappableAspectInterface
{
protected $settings;
public function __construct(array $settings)
{
$this->settings = $settings;
}
public function generate(string $value): ?string
{
return $value;
}
public function resolve(string $value): ?string
{
return strstr($value, '/') ? null : $value;
}
}