Beispiel #1
0
 public function run()
 {
     $dispatcher = Flow::app()->getComponent('url_router');
     $action_name = $dispatcher->getAction();
     $method_name = $dispatcher->getMethod();
     $action_name = ucfirst($action_name) . "Controller";
     // 检测是否存在
     if (empty(FLow::$classMap[$action_name])) {
         if (DEV_MODE) {
             header("HTTP/1.1 404 Not Found");
             throw new Exception("Controller {$action_name} Not Found");
         } else {
             header("HTTP/1.1 404 Not Found");
             die;
         }
     }
     $action = Flow::app()->createComponent(array('class' => $action_name, 'view' => Flow::app()->view_engine, 'request' => Flow::app()->getComponent('request')));
     $action->beforeController();
     $method_name = "action" . $method_name;
     // 检测方法
     if (!method_exists($action, $method_name)) {
         if (DEV_MODE) {
             header("HTTP/1.1 404 Not Found");
             throw new Exception("Controller {$action_name} has No {$method_name} Method");
         } else {
             header("HTTP/1.1 404 Not Found");
             die;
         }
     }
     // 执行方法
     $action->{$method_name}();
 }
Beispiel #2
0
 public function actionIndex()
 {
     FLow::app()->request->getText("a");
     $entry_acm = Flow::app()->acf->table("entry");
     $comicnodes = $entry_acm->where("cat='cartoon'")->order("publish_date desc, `dsr_score` desc")->limit("30")->findall();
     $movienodes = $entry_acm->where("cat='movie'")->order("publish_date desc, `dsr_score` desc")->limit("30")->findall();
     $this->assign("comicnodes", $comicnodes);
     $this->assign("movienodes", $movienodes);
     $this->display();
 }
Beispiel #3
0
 private function _routeRequest()
 {
     $action = isset(Flow::$cfg['default_controller']) ? Flow::$cfg['default_controller'] : "index";
     $method = 'index';
     $base_path = Flow::app()->basePath;
     $uri = $_SERVER['REQUEST_URI'];
     if (strpos($uri, $base_path) === 0) {
         $uri = substr($uri, strlen($base_path));
     }
     // 如果有pattern 用pattern的匹配
     if (!empty($this->rewrite_rules)) {
         foreach ($this->rewrite_rules as $url_pattern => $dest) {
             $uri = preg_replace($url_pattern, $dest, $uri);
             break;
         }
     }
     $uri_parsed = parse_url($uri);
     if (empty($uri_parsed['path'])) {
         $uri_parsed['path'] = '/';
     }
     // 按斜杠分拆
     $params = explode("/", trim($uri_parsed['path'], "/\\"));
     if (!empty($params[0])) {
         $action = $params[0];
         if (strpos($action, '.') !== false) {
             $action = 'Main';
         }
     }
     if (!empty($params[1])) {
         $method = $params[1];
     }
     if (!empty($_GET['action'])) {
         $action = $_GET['action'];
     }
     if (!empty($_GET['method'])) {
         $method = $_GET['method'];
     }
     // 多余的参数设置到请求里面
     foreach ($params as $i => $j) {
         if ($i % 2 == 1 && $i != 0) {
             if ($params[$i - 1] != "") {
                 $_GET[$params[$i - 1]] = $params[$i];
             }
         }
     }
     $this->action = $action;
     $this->method = $method;
 }
Beispiel #4
0
 public function actionIndex()
 {
     header('Location:' . Flow::app()->basePath . '/test/b');
     $this->display();
 }
Beispiel #5
0
 public function init()
 {
     $this->setView(Flow::app()->view_engine);
     $this->request = Flow::app()->request;
 }