drupal 8:如何使用路由参数重定向路由?

时间:2018-09-18 16:34:09

标签: drupal-8

我已经在drupal8中使用参数创建了动态路由。现在,我需要根据用户操作重定向到此页面。如何实现?

页面示例路由器代码如下例:

domain_site_settings.config_form:
  path: '/admin/config/domain/domain_site_settings/{domain_id}/edit'
  defaults:
    _form: '\Drupal\domain_site_settings\Form\DomainConfigSettingsForm'
    _title: 'Domain site settings'
  requirements:
    _permission: 'domain site settings'
  options:
    _admin_route: TRUE

2 个答案:

答案 0 :(得分:0)

最后我找到了这个问题的答案。

use Symfony\Component\HttpFoundation\RedirectResponse;

$path = \Drupal\Core\Url::fromRoute('domain_site_settings.config_form',
    ['domain_id' => 'drupal_com'])->toString();
  $response = new RedirectResponse($path);
  $response->send();

答案 1 :(得分:0)

use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;  


$url = Url::fromRoute('YOUR CUSTOM ROUTE');
  $query = [
    'searchQuery' => [
      'searchType' => $searchType,
      'title'      => $title,
    ],
  ];
  $path = $url->setOption('query', $query);
  $path = $path->toString();

  $response = new RedirectResponse($path);
  $response->send();