Solved! Child route with hostname parent route, wrong in url built-in viewhelper

route defined in module.config.php as follow:

'router' => [
	'routes' => [
		'searchtop' => [
			'type' => Hostname::class,
			'options' => [
				'route' => ':subdomain.:maindomain',
				'constraints' => [
					'subdomain' => 'so',
					'maindomain' => 'somedomain.com',
				],
				'defaults' => [
					'controller' => Controller\IndexController::class,
					'action'     => 'index',
				],
			],
			'may_terminate' => true,
			'child_routes' => [
				'home' => [
					'type'    => Literal::class,
					'options' => [
						'route'    => '/',
						'defaults' => [
							'controller' => Controller\IndexController::class,
							'action'     => 'index',
						],
					],
				],
				'searchpcresult' => [
					'type' => Literal::class,
					'options' => [
						'route' => '/pc/ss',
						'defaults' => [
							'controller' => Controller\SearchController::class,
							'action' => 'pcsub',
						],
					],
				],
				'searchmresult' => [
					'type' => Literal::class,
					'options' => [
						'route' => '/m/ss',
						'defaults' => [
							'controller' => Controller\SearchController::class,
							'action' => 'msub',
						],
					],
				],
			],
		],
	],
],

When I use the following in my viewhelper like, error raise.

$view = $this->getView();
return $view->url($this->routeName, $this->paramsArr, ['query' => $queryArr]);   // $this->routeName here is **searchtop/searchpcresult**

Unfortunately, we can’t look at your screen, so the full error message would be very helpful. Otherwise it will be difficult for us to help you.

1 Like

thanks for your reply! the problem solved!

I surround the $view->url with try catch, then it tell why raise error. I fixed by following the guide.

And? What was the error?

(Please remember, the forum is not a one-way street. Your insights and solutions can also help others. Thanks in advance!)

Spelling mistake! The developer curse! :rofl:

1 Like