Example #1
0
 public function redirect($path = '', $useBaseUrl = true, $permanent = false)
 {
     $fullPath = $path;
     $config = Model3_Registry::get('config');
     $configData = $config->getArray();
     if ($configData['m3_internationalization']['inter_multilang'] == true) {
         $fullPath = $configData['m3_internationalization']['inter_default_lang'] . '/' . $path;
     }
     if ($useBaseUrl == true) {
         $fullPath = $this->_request->getBaseUrl() . '/' . $fullPath;
     }
     if ($permanent == true) {
         header("HTTP/1.1 301 Moved Permanently");
     }
     header('Location: ' . $fullPath);
     exit;
 }
Example #2
0
 public static function loadTemplate($view, $layout = NULL)
 {
     if (!empty($layout)) {
         ob_start();
     }
     $exists = false;
     $absController = self::$_request->getController();
     if (self::$_request->isModule()) {
         $absController = self::$_request->getModule() . '_' . self::$_request->getController();
     }
     $templatefile = 'View/Scripts/' . str_replace("_", "/", $absController) . '/' . self::$_request->getAction() . '.php';
     $path = explode(PATH_SEPARATOR, get_include_path());
     foreach ($path as $tryThis) {
         $exists = file_exists($tryThis . $templatefile);
         if ($exists) {
             include_once $tryThis . $templatefile;
             break;
         }
     }
     if (!$exists) {
         $templatefile = 'View/Scripts/' . str_replace("_", "/", $absController) . '/_default.php';
         $path = explode(PATH_SEPARATOR, get_include_path());
         foreach ($path as $tryThis) {
             $exists = file_exists($tryThis . $templatefile);
             if ($exists) {
                 include_once $tryThis . $templatefile;
                 break;
             }
         }
     }
     if (!$exists) {
         throw new Exception("View '{$templatefile}' is not found in View/Scripts/ directory.");
     }
     if (!empty($layout)) {
         $layoutdata = ob_get_clean();
         $layoutfile = 'View/Layout/' . $layout . '.php';
         $path = explode(PATH_SEPARATOR, get_include_path());
         foreach ($path as $tryThis) {
             $exists = file_exists($tryThis . $layoutfile);
             if ($exists) {
                 include_once $tryThis . $layoutfile;
                 break;
             }
         }
         if (!$exists) {
             throw new Exception('Template ' . $layoutfile . ' is not found in View/Layout directory.');
         }
     }
 }
Example #3
0
 /**
  *
  * @param array|null $options
  * @param bool $propague
  * @return string
  */
 public function url($options = null, $propague = false)
 {
     $reset = false;
     $strlenController = 0;
     $strlenAction = 0;
     if ($options == null) {
         $options = array();
     }
     $url = $this->_baseUrl . '/';
     $config = Model3_Registry::get('config');
     $configData = $config->getArray();
     if ($configData['m3_internationalization']['inter_multilang'] == true) {
         if (array_key_exists('lang', $options)) {
             $url .= $options['lang'];
             $url .= '/';
         } else {
             $url .= $this->_request->getLang();
             $url .= '/';
         }
     }
     if (array_key_exists('component', $options)) {
         if ($options['component'] != null) {
             $url .= $options['component'];
             $url .= '/';
             $reset = true;
         }
         unset($options['component']);
     } else {
         if ($this->_request->isComponent()) {
             $url .= $this->_request->geComponent();
             $url .= '/';
         }
     }
     if (array_key_exists('module', $options)) {
         if ($options['module'] != null) {
             $url .= $options['module'];
             $url .= '/';
             $reset = true;
         }
         unset($options['module']);
     } else {
         if ($this->_request->isModule()) {
             $url .= $this->_request->getModule();
             $url .= '/';
         }
     }
     if (array_key_exists('controller', $options)) {
         if ($options['controller'] != null) {
             $url .= $options['controller'];
             if ($options['controller'] == 'Index') {
                 $strlenController = strlen($url);
             }
             $reset = true;
         }
         unset($options['controller']);
     } else {
         if (!$reset) {
             $url .= $this->_request->getController();
         } else {
             $url .= 'Index';
             $strlenController = strlen($url);
         }
     }
     $url .= '/';
     if (array_key_exists('action', $options)) {
         if ($options['action'] != null) {
             $url .= $options['action'];
             if ($options['action'] == 'index') {
                 $strlenController = strlen($url);
             }
         }
         unset($options['action']);
     } else {
         if (!$reset) {
             $url .= $this->_request->getAction();
         } else {
             $url .= 'index';
             $strlenAction = strlen($url);
         }
     }
     $url .= '/';
     if ($propague == true) {
         $params = $this->_request->getParams();
         foreach ($params as $key => $param) {
             if (array_key_exists($key, $options)) {
                 if ($options[$key] != null) {
                     $url .= $key . '/';
                     $url .= $options[$key];
                     $url .= '/';
                 }
                 unset($options[$key]);
             } else {
                 $url .= $key . '/';
                 $url .= $param;
                 $url .= '/';
             }
         }
     }
     foreach ($options as $key => $option) {
         $url .= $key . '/' . $option . '/';
     }
     /**
      * Limpiaremos la url en caso de que termine en index/ o en Index/index/
      */
     if ($strlenAction != 0 && $strlenAction + 1 == strlen($url)) {
         if ($strlenController != 0 && $strlenController + 1 == strlen($url)) {
             $url = substr($url, 0, $strlenController - 5);
         } else {
             $url = substr($url, 0, $strlenAction - 5);
         }
     }
     return $url;
 }