Zend framework ZF:自定义管线,将所有零件制作为参数

Zend framework ZF:自定义管线,将所有零件制作为参数,zend-framework,zend-route,zend-controller-router,Zend Framework,Zend Route,Zend Controller Router,希望有人能帮我 我有一个Zend路由器,可以处理向篮子中添加东西。现在我正在构建一个customiser模块,这样用户就可以在产品的指定部分添加任意多个不同颜色的部件 我的基本url是这样的 http://www.domain.com/shop/add/custom/size/type resources.router.routes.shopAddCustom.route = shop/add/custom/:size/:type/* resources.router.routes.shopA

希望有人能帮我

我有一个Zend路由器,可以处理向篮子中添加东西。现在我正在构建一个customiser模块,这样用户就可以在产品的指定部分添加任意多个不同颜色的部件

我的基本url是这样的

http://www.domain.com/shop/add/custom/size/type
resources.router.routes.shopAddCustom.route = shop/add/custom/:size/:type/*
resources.router.routes.shopAddCustom.defaults.module = shop
resources.router.routes.shopAddCustom.defaults.controller = order
resources.router.routes.shopAddCustom.defaults.action = add
resources.router.routes.shopAddCustom.defaults.product = builder
array('part3' => 'blue', 'right' => 'part2', 'part6' => 'both' [...] );
我当前的router.ini是这样的

http://www.domain.com/shop/add/custom/size/type
resources.router.routes.shopAddCustom.route = shop/add/custom/:size/:type/*
resources.router.routes.shopAddCustom.defaults.module = shop
resources.router.routes.shopAddCustom.defaults.controller = order
resources.router.routes.shopAddCustom.defaults.action = add
resources.router.routes.shopAddCustom.defaults.product = builder
array('part3' => 'blue', 'right' => 'part2', 'part6' => 'both' [...] );
我真正想要的是像这样的URL

http://www.domain.com/shop/add/custom/size/type/part3/blue/right/part2/part6/both/part7/red/part1/left/orange/
基本上,尺寸/类型/背后的所有内容都是一个零件、一种颜色或一个部分(右、左、两者)

如何获得大小/类型之后所有url路径部分的单个数组

array(0 => 'part3', 1 => 'blue', 2 => 'right', 3 => 'part2', 4 => 'part6' [...] );
如果我只是使用
$this-_request->getParams()我得到这样一个数组

http://www.domain.com/shop/add/custom/size/type
resources.router.routes.shopAddCustom.route = shop/add/custom/:size/:type/*
resources.router.routes.shopAddCustom.defaults.module = shop
resources.router.routes.shopAddCustom.defaults.controller = order
resources.router.routes.shopAddCustom.defaults.action = add
resources.router.routes.shopAddCustom.defaults.product = builder
array('part3' => 'blue', 'right' => 'part2', 'part6' => 'both' [...] );
我可以运行该数组,将所有键和值作为值添加到新数组中。问题是,如果url路径部分的数量为奇数,则最后一部分将不会返回给params,因为它被视为一个空变量,因此不会添加到params数组中


任何想法都是值得赞赏的:)

好吧,这就是我认为我可以做到的——任何其他解决方案都是受欢迎的

$size = $this->_getParam('size');
$type = $this->_getParam('type');

$baseRouterUrl = $this->_helper->url->url(array('size' => $size, 'type' => $type), 'shopAddCustom', true);
$pathInfo = dirname($this->_request->getPathInfo() . '/.');

$pathInfo = str_replace($baseRouterUrl, '', '/' . $pathInfo);
$pathInfo = trim($pathInfo, '/\\');

$pathArr = explode('/', $pathInfo);
这是结果数组

array(11) {
  [0]=>
  string(5) "part3"
  [1]=>
  string(4) "blue"
  [2]=>
  string(5) "right"
  [3]=>
  string(5) "part2"
  [4]=>
  string(5) "part6"
  [5]=>
  string(4) "both"
  [6]=>
  string(5) "part7"
  [7]=>
  string(3) "red"
  [8]=>
  string(5) "part1"
  [9]=>
  string(4) "left"
  [10]=>
  string(6) "orange"
}

好吧,这就是我认为我可以做到这一点-任何其他解决方案仍然欢迎

$size = $this->_getParam('size');
$type = $this->_getParam('type');

$baseRouterUrl = $this->_helper->url->url(array('size' => $size, 'type' => $type), 'shopAddCustom', true);
$pathInfo = dirname($this->_request->getPathInfo() . '/.');

$pathInfo = str_replace($baseRouterUrl, '', '/' . $pathInfo);
$pathInfo = trim($pathInfo, '/\\');

$pathArr = explode('/', $pathInfo);
这是结果数组

array(11) {
  [0]=>
  string(5) "part3"
  [1]=>
  string(4) "blue"
  [2]=>
  string(5) "right"
  [3]=>
  string(5) "part2"
  [4]=>
  string(5) "part6"
  [5]=>
  string(4) "both"
  [6]=>
  string(5) "part7"
  [7]=>
  string(3) "red"
  [8]=>
  string(5) "part1"
  [9]=>
  string(4) "left"
  [10]=>
  string(6) "orange"
}

我现在用这个,在它很棒的时候:)我现在用这个,在它很棒的时候:)