правильное использование языков в zend framework

У меня есть приложение Zend с двумя модулями (admin и public), а для общедоступных у меня есть следующий плагин для анализа моего дружественного URL:

class Custom_Controller_Plugin_Initializer extends Zend_Controller_Plugin_Abstract {

    protected $_front;
    protected $_request;

    public function __construct() {
        $this->_front = Zend_Controller_Front::getInstance();
        $this->_request = $this->_front->getRequest();        
    }

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
    //checking if the url ends with "/"      
        $requestUri = $this->_request->getRequestUri();
        $path = parse_url($requestUri, PHP_URL_PATH);
        $query = parse_url($requestUri, PHP_URL_QUERY);
        if (substr($path, -1) != '/') {
            header('location: ' . $path . (isset($query) ? '/?' . $query : '/'));
            die();
        }
// exploding the uri to get the parts.        
        $uri = explode('/', substr($path, strlen(Zend_Controller_Front::getInstance()->getBaseUrl()) + 1));


        $modelLanguage = new Model_Db_Language();
    //checking if the first part is of 2 characters and if it's a registered language
        if ($modelLanguage->checkLanguage($uri[0])) {            
            $language = $uri[0];
            unset($uri[0]); //deleting the language from the uri.
            $uri = array_values($uri);
        } else {
            $language = $modelLanguage->autoLanguage();
            if (!$uri[0] == '' && (strlen($uri[0]) == 2)) {
                $uri[0] = $language;
                header('location: ' . Zend_Controller_Front::getInstance()->getBaseUrl() . '/' . implode($uri) . (isset($query) ? '/?' . $query : '/'));
                die();
            }
        }

//remember that the language was deleted from the uri
        $this->_request->setParam('requestUri', implode('/', $uri));

        switch ($uri[0]) {
            case 'search':
                unset($uri[0]);
                $this->_request->setParam('s', urldecode($uri[2]));
                $this->_request->setModuleName('public');
                $this->_request->setControllerName('content');
                $this->_request->setActionName('search');
                $this->_request->setParam('template', 'search');
                break;
        }
        $this->_initTranslation($language);
            $this->_initInterface();
}}

Это очень полезно, если я хочу использовать такую ​​структуру, как domain.com/en/about-us/mision/ , потому что я могу проанализировать URL-адрес и получить первый параметр «en», а после этого найти страницу, связанную с «about-us / mission», но что если Я хочу использовать domain.com/en/user/profile/id/1/ , Zend установил « en » в качестве контроллера и « пользователя [1 1100293] "как действие.Как я могу правильно установить язык в URL-адресе?

5
задан José Carlos 9 June 2011 в 21:09
поделиться