Exemple #1
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 = '../src/App/View/Scripts/' . str_replace("_", "/", $absController) . '/' . self::$_request->getAction() . '.php';
     $exists = file_exists($templatefile);
     if ($exists) {
         include_once $templatefile;
     }
     if (!$exists) {
         $templatefile = '../src/App/View/Scripts/' . str_replace("_", "/", $absController) . '/_default.php';
         $exists = file_exists($templatefile);
         if ($exists) {
             include_once $templatefile;
         }
     }
     if (!$exists) {
         throw new Model3Exception("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 Model3Exception('Template ' . $layoutfile . ' is not found in View/Layout directory.');
         }
     }
 }
Exemple #2
0
 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;
 }