示例#1
0
文件: View.php 项目: thupan/framework
 public static function flash($message, $alert = 'info')
 {
     Session::set('flash', XHR::alert($message, $alert));
 }
示例#2
0
 public static function autoDispatch()
 {
     self::uri_prepare();
     if (strpos(self::$uri, '/') === 0) {
         self::$uri = substr(self::$uri, strlen('/'));
     }
     self::$uri = trim(self::$uri, '/');
     self::$uri = ($amp = strpos(self::$uri, '&')) !== false ? substr(self::$uri, 0, $amp) : self::$uri;
     $parts = explode('/', self::$uri);
     self::$controller = array_shift($parts);
     self::$method = array_shift($parts);
     self::$controller = self::$controller ? self::$controller : DEFAULT_CONTROLLER;
     self::$method = self::$method ? self::$method : self::DEFAULT_METHOD;
     self::$args = !empty($parts) ? $parts : array();
     $ControllerClass = ucfirst(self::$controller) . 'Controller';
     if (!file_exists(DOC_ROOT . "app/Http/Controllers/{$ControllerClass}.php")) {
         return false;
     }
     self::$controller = "\\App\\Http\\Controllers\\{$ControllerClass}";
     $controller = new self::$controller();
     // verifica os filtros
     if (self::$filter) {
         foreach (self::$filters as $action => $name) {
             foreach ($name as $callback) {
                 if (self::BEFORE === $action) {
                     $callback();
                 }
             }
         }
         if (method_exists($controller, self::$method)) {
             call_user_func_array(array($controller, self::$method), self::$args);
             return true;
         } else {
             $method = explodeCamelCase(self::$method);
             if ($method[0] !== 'xhr') {
                 call_user_func_array(array($controller, self::DEFAULT_METHOD), self::$args);
             } else {
                 echo '<tr><td colspan="30">' . XHR::alert('Oopss, ocorreu um erro ao carregar o método <b>' . self::$method . '</b>. verifique sua chamada javascript ou se o método xhr existe no seu respectivo controlador.', 'danger') . '</td></tr>';
             }
         }
     } else {
         if (method_exists($controller, self::$method)) {
             call_user_func_array(array($controller, self::$method), self::$args);
             return true;
         } else {
             $method = explodeCamelCase(self::$method);
             if ($method[0] !== 'xhr') {
                 call_user_func_array(array($controller, self::DEFAULT_METHOD), self::$args);
             } else {
                 echo '<tr><td colspan="30">' . XHR::alert('Oopss, ocorreu um erro ao carregar o método <b>' . self::$method . '</b>. verifique sua chamada javascript ou se o método xhr existe no seu respectivo controlador.', 'danger') . '</td></tr>';
             }
         }
     }
     return false;
 }