public function setGotoRoute(array $urlOptions = array(), $name = null, $reset = false, $encode = true) { $router = $this->getFrontController()->getRouter(); $currentModule = Zend_Controller_Front::getInstance()->getRequest()->getModuleName(); if ($currentModule !== 'frontend') { $url = $router->assemble($urlOptions, $name, $reset, $encode); $this->_redirect($url); } $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $tempPageParams = array(); if (array_key_exists('page', $urlOptions)) { $controller = isset($urlOptions['controller']) ? $urlOptions['controller'] : 'index'; $action = isset($urlOptions['action']) ? $urlOptions['action'] : 'index'; foreach ($urlOptions as $key => $value) { if (!in_array($key, array('module', 'controller', 'action')) && !($key == 'id' && $controller == 'category' && $action == 'products') && !($key == 'brandId' && $controller == 'brand' && $action == 'brandproducts')) { $tempPageParams[$key] = $value; unset($urlOptions[$key]); } } } $url = $router->assemble($urlOptions, $name, $reset, $encode); $urlAliasModel = new UrlAlias(); $source = $urlAliasModel->getUriFromUrl($url, $view->baseUrl()); $alias = $urlAliasModel->getAliasBySource($source); if (count($tempPageParams) > 0 && $alias == $source) { $this->_redirect($router->assemble($tempPageParams + $urlOptions, $name, $reset, $encode)); } $this->_redirect($view->baseUrl() . '/' . $alias . (count($tempPageParams) == 0 ? '' : $this->stringifyParams($tempPageParams))); }
public function url(array $urlOptions = array(), $name = 'default', $reset = true, $encode = true) { $router = Zend_Controller_Front::getInstance()->getRouter(); $currentModule = Zend_Controller_Front::getInstance()->getRequest()->getModuleName(); if ($currentModule != 'frontend') { return $router->assemble($urlOptions, $name, $reset, $encode); } $tempPageParams = array(); if (array_key_exists('page', $urlOptions)) { $controller = isset($urlOptions['controller']) ? $urlOptions['controller'] : 'index'; $action = isset($urlOptions['action']) ? $urlOptions['action'] : 'index'; foreach ($urlOptions as $key => $value) { if (!in_array($key, array('module', 'controller', 'action'))) { $tempPageParams[$key] = $value; unset($urlOptions[$key]); } } } $url = $router->assemble($urlOptions, $name, $reset, $encode); $urlAliasModel = new UrlAlias(); $source = $urlAliasModel->getUriFromUrl($url, $this->view->baseUrl()); $alias = $urlAliasModel->getAliasBySource($source); // echo $source.'ddd';die; if (count($tempPageParams) > 0 && $alias == $source) { return $router->assemble($tempPageParams + $urlOptions, $name, $reset, $encode); } // echo $this->view->baseUrl() . '/' . $alias . ((count($tempPageParams) == 0) ? '' : $this->stringifyParams($tempPageParams));die; return $this->view->baseUrl() . '/' . $alias . (count($tempPageParams) == 0 ? '' : $this->stringifyParams($tempPageParams)); }
/** * Init Request * @return Zend_Controller_Request_Http */ protected function _initRequest() { if (CURRENT_MODULE == 'frontend') { $front = Zend_Controller_Front::getInstance(); $request = new Zend_Controller_Request_Http(); $front->setRequest($request); $router = $front->getRouter(); $route = new Zend_Controller_Router_Route_Static('dsrpc.html', array('controller' => 'wsclientpoint', 'action' => 'index')); $rewriteUrlArray = array(); $rewriteUrlArray[''] = array('controller' => 'index', 'action' => 'index'); $auth = Zend_Auth::getInstance(); foreach ($rewriteUrlArray as $key => $value) { $router->addRoute($key, new Zend_Controller_Router_Route_Static($key, array('controller' => $value['controller'], 'action' => $value['action']))); } $urlAliasModel = new UrlAlias(); $url = $request->getRequestUri(); /** * If the alias contains a pagination */ $pagePosition = strpos($url, '--page-'); $pageParams = array(); if ($pagePosition !== false) { $stringParams = substr($url, $pagePosition + 2, strlen($url)); $pageParams = explode('-', $stringParams); $url = substr($url, 0, $pagePosition); } /** * /If */ $alias = $urlAliasModel->getUriFromUrl($url, $request->getBaseUrl()); $aliasItem = $urlAliasModel->getByAlias($alias); //var_dump($aliasItem->params);die; if ($aliasItem !== false) { $paramArray = (array) json_decode($aliasItem->params); if (count($pageParams) > 0) { $alias .= '-'; $i = 0; foreach ($pageParams as $param) { $alias .= '-' . $param; if ($i % 2 == 0 && $pageParams[$i + 1] != '') { $paramArray[$param] = $pageParams[$i + 1]; } $i++; } } $router->addRoute($alias, new Zend_Controller_Router_Route_Static($alias, $paramArray)); } /** * Rewrite the captchas path */ $route = new Zend_Controller_Router_Route('captcha/:filename', array('controller' => 'file', 'action' => 'getcaptcha')); $router->addRoute('captchas', $route); return $request; } }