Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework2 zend framework 2路由配置和参数传递_Zend Framework2 - Fatal编程技术网

Zend framework2 zend framework 2路由配置和参数传递

Zend framework2 zend framework 2路由配置和参数传递,zend-framework2,Zend Framework2,我启动了一个zend2项目,但我不知道路由系统。我真的需要一些帮助,将一些变量从视图传递回控制器。模块配置如下所示: <?php return array( 'controllers' => array( 'invokables' => array( 'Map\Controller\Index' => 'Map\Controller\IndexController', ), ), 'router' => array( 'rou

我启动了一个zend2项目,但我不知道路由系统。我真的需要一些帮助,将一些变量从视图传递回控制器。模块配置如下所示:

<?php
return array(
'controllers' => array(
    'invokables' => array(
        'Map\Controller\Index' => 'Map\Controller\IndexController',
    ),
),
'router' => array(
    'routes' => array(
        'map' => array(
            'type'    => 'segment',
            'options' => array(
                // Change this to something specific to your module
                'route'    => '/map[/:action][/:tileId]',
                'defaults' => array(
                    // Change this value to reflect the namespace in which
                    // the controllers for your module are found
                    '__NAMESPACE__' => 'Map\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                // This route is a sane default when developing a module;
                // as you solidify the routes for your module, however,
                // you may want to remove it and replace it with more
                // specific routes.
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        'map' => __DIR__ . '/../view',
    ),
),
);
类似的问题是,我尝试“myappname.dev/map/buy tile”,它进入方法并打印字符串,但当我尝试传递“myappname.dev/map/buy tile/tileId/1”这样的参数时,我在控制器中没有收到值


提前谢谢你

这应该是你需要做的

public function buyTileAction() {
    $tileId = $this->params()->fromRoute('tileId');
}
尝试:

您好,尝试了两种解决方案(@Adam H's和@KeyneON's),没有一种给我预期的结果。请求没有打印变量的值,而是给出了一个“请求的URL无法通过路由匹配”。当我尝试访问myappname.dev/map/buy-tile/tileId/1时,有人知道如何解决这个问题吗?非常感谢。
public function buyTileAction() {
    $tileId = $this->params()->fromRoute('tileId');
}
$tileId = $this->getEvent()->getRouteMatch()->getParam('tileId');