所以這是我在我的引導文件Zend的翻譯+自定義網址
/*
* Here the Translator is enabled and passed to
* Zend_Registry so can be accesed from anywhere
*/
public static function translateOption()
{
Zend_Loader::loadClass('Zend_Translate');
$translate = new Zend_Translate(
'Zend_Translate_Adapter_Csv',
self::$root."/lang/en/language.csv",
'en');
self::$registry->translate = $translate;
}
我試圖才達到像mysite.com/language/controller/action一個URL
這是我的路線。
;Multilang routes
lang_default.type = "iM_Controller_Router_Route_Language"
lang_default.route = ":language/:controller/:action/*"
lang_default.defaults.module = default
lang_default.defaults.controller = index
lang_default.defaults.action = index
lang_default.defaults.language = en
lang_default.reqs.language = "(ro|en)"
這裏是路由控制器插件,我發現在互聯網上:
<?php
/**
* Front Controller Plugin; Created by Gabriel Solomon (http://www.gsdesign.ro/blog/optimizing-zend-routing/)
*
* @uses Zend_Controller_Plugin_Abstract
* @category iM
* @package iM_Controller
* @subpackage Plugins
*/
class iM_Controller_Plugin_Router extends Zend_Controller_Plugin_Abstract{
protected $_dir;
protected $_default = array();
protected $_request;
protected $_initialConfig;
protected $_remainingConfig;
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
// define some routes (URLs)
$router = Zend_Controller_Front::getInstance()->getRouter();
$this->setRequest($request);
$config = $this->getInitial();
$router->addConfig($config);
}
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$config = $this->getRemaining();
$router->addConfig($config);
}
public function setDir($dir) {
$this->_dir = $dir;
}
public function setDefault($default) {
if (is_array($default)) {
$this->_default = array_merge($this->_default, $default);
} else {
$this->_default[] = $default;
}
}
public function setRequest(Zend_Controller_Request_Abstract $request) {
$this->_request = $request;
//return $this;
}
public function getInitial() {
if ($this->_initialConfig == null) {
$this->parseIniDir();
}
return $this->_initialConfig;
}
public function getRemaining() {
if ($this->_remainingConfig == null) {
$this->parseIniDir();
}
return $this->_remainingConfig;
}
protected function parseIniDir() {
$files = $this->getFiles();
$this->_default;
$this->_default[] = $this->determineInitial();
$this->_initialConfig = new Zend_Config(array(), true);
$this->_remainingConfig = new Zend_Config(array(), true);
if (is_array($files)) {
foreach ($files as $file) {
$routerFile = $this->compilePath($file);
if (in_array($file, $this->_default)) {
$this->_initialConfig->merge(new Zend_Config_Ini($routerFile));
} else {
$this->_remainingConfig->merge(new Zend_Config_Ini($routerFile));
}
}
}
}
protected function getFiles() {
if (is_dir($this->_dir)) {
$dir = new DirectoryIterator($this->_dir);
$files = array();
foreach($dir as $fileInfo) {
if(!$fileInfo->isDot() && $fileInfo->isFile()) {
$files[] = $fileInfo->__toString();
}
}
return $files;
}
return false;
}
protected function getOtherRoutes() {
$routes->merge(new Zend_Config_Ini($routerFile));
}
protected function determineInitial() {
if ($this->_request) {
$uri = $this->_request->getRequestUri();
$base = $this->_request->getBasePath() . '/';
$request = str_replace($base, '', $uri);
$requestParts = explode('/', $request);
$lang = $requestParts[0];
(array_key_exists(1,$requestParts) ? $section = $requestParts[1] : $section = '');
if (!empty($section) && $section == 'user') {
return 'user.ini';
}
}
return false;
}
protected function compilePath($file) {
return $this->_dir . '/' . $file;
}
}
現在我的問題是,我該如何改變語言,如果URL/EN或/ RO或/德我想我必須改變它的引導程序功能translateOption
但如何,我也想提一下,這也有一些錯誤...但我現在會很高興如果你能幫助我如何改變語言,如果網址更改,謝謝!
我不知道是否有人會讀這...但希望如此