2

我有以下路由定义:

'admin_default' => array( 
    'type'    => 'segment', 
    'options' => array( 
        'route'    => '[/:lang]/administrator[/:module][/:action]', 
        'constraints' => array( 
            'lang' => '[a-zA-Z]{2}', 
            'module' => '[a-zA-Z0-9_-]*', 
            'action' => '[a-zA-Z0-9_-]*', 
        ), 
        'defaults' => array( 
            'module' => 'Application', 
            'controller' => 'Admin', 
            'action'     => 'index', 
            'lang' => 'ru' 
        ), 
    ), 
    'may_terminate' => true, 
    'child_routes'  => array( 
        'wildcard' => array( 
            'type' => 'wildcard', 
            'may_terminate' => true, 
            'options' => array( 
                'key_value_delimiter' => '/', 
                'param_delimiter' => '/' 
             ), 
        ), 
    ), 
), 

所以,我无法摆脱 URL 字符串中的段 [/:lang]

例如:

URL 视图助手$this->url('admin_default', array('module' => 'albums'))返回以下 URL 字符串:

/administrator/albums 

$this->url('admin_default/wildcard', array('module' => 'albums', 'action' => 'edit', 'id' => album_id_here))返回:

/ru/administrator/albums/edit/id/album_id_here 

在第二种情况下,如何从 URL 字符串中删除 [/:lang] 段?

4

1 回答 1

0

那么那个“ru”是怎么回事?

您必须扩展 zend 视图帮助程序 URL 以将您当前的语言环境注入到 URL

看看我为我目前的项目做了什么:

    <?php

namespace PatrickCore\View\Helper;

use Doctrine\ORM\EntityManager;
use Zend\View\Helper\Url;

class I18nUrl extends Url {

    /**
     * @var String
     */
    protected $lang;
    protected $router;

    public function __construct($locale,$router) {

        $arraylanguagemapping = array(
            'en_US' => 'en',
            'fa_IR' => 'fa'
        );
        $this->lang = $arraylanguagemapping[$locale];
        $this->router = $router;
    }

    public function __invoke($name = null, array $params = array(), $options = array(), $reuseMatchedParams = false) {

        $this->setRouter($this->router);

        if (!array_key_exists('lang', $params)) {
            $params['lang'] = $this->lang;
        }


        return parent::__invoke($name,$params,$options,$reuseMatchedParams);

    }

}

?>
于 2013-04-03T12:54:05.733 回答