Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

路由的自定义方面未按预期工作

我已经编写了一个自定义方面的代码,应该将其传递回去。这部分起作用:

加工

?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;
    }
} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

将类更改为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;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...