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

**URL:** <https://discourse.laminas.dev/t/solved-child-route-with-hostname-parent-route-wrong-in-url-built-in-viewhelper/3394>\
**Category:** Components & MVC\
**Tags:** laminas-router\
**Created:** [July 17, 2023, 1:53am UTC](https://discourse.laminas.dev/t/solved-child-route-with-hostname-parent-route-wrong-in-url-built-in-viewhelper/3394 "2023-07-17T01:53:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jobsfan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/jobsfan/32/399_2.png) [@jobsfan](https://discourse.laminas.dev/u/jobsfan)\
**Post date:** [July 17, 2023, 1:53am UTC](https://discourse.laminas.dev/t/solved-child-route-with-hostname-parent-route-wrong-in-url-built-in-viewhelper/3394/1 "2023-07-17T01:53:15Z")

</div>

route defined in module.config.php as follow:

```auto
'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.

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

```

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [July 18, 2023, 10:23am UTC](https://discourse.laminas.dev/t/solved-child-route-with-hostname-parent-route-wrong-in-url-built-in-viewhelper/3394/2 "2023-07-18T10:23:11Z")

</div>

> [@jobsfan](#):
>
> …error raise.

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.

---

<div class="post-metadata">

**Author:** ![jobsfan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/jobsfan/32/399_2.png) [@jobsfan](https://discourse.laminas.dev/u/jobsfan)\
**Post date:** [July 31, 2023, 5:28am UTC](https://discourse.laminas.dev/t/solved-child-route-with-hostname-parent-route-wrong-in-url-built-in-viewhelper/3394/3 "2023-07-31T05:28:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [July 31, 2023, 6:09am UTC](https://discourse.laminas.dev/t/solved-child-route-with-hostname-parent-route-wrong-in-url-built-in-viewhelper/3394/4 "2023-07-31T06:09:01Z")

</div>

> [@jobsfan](#):
>
> …then it tell why raise error.

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!)

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [August 1, 2023, 8:33am UTC](https://discourse.laminas.dev/t/solved-child-route-with-hostname-parent-route-wrong-in-url-built-in-viewhelper/3394/5 "2023-08-01T08:33:48Z")

</div>

Spelling mistake! The developer curse! 🤣
