因为您试图通过请求 myproject.local/1234 来解决未配置的路由,所以如果您想将 1234 作为参数传递给您的索引控制器(主路由),请设置从该行请求的路由,如下所示:
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/[:myparam]',
'constraints' => array(
'id' => '\d*',
),
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
现在您可以在 IndexController 中获取 myparam,如下所示:
public function indexAction()
{
$myparam = (int) $this->params()->fromRoute('myparam', 0);
var_dump($myparam); // Prints 123 on myproject.localhost/123 and 0 on myproject.localhost
exit; // Exit for just simply show the logic. Don't use exit in controller like this.
}