예제 #1
0
 public function dispatch($action)
 {
     mtrace('mcontroller::dispatch = ' . $action);
     if (!method_exists($this, $action)) {
         mtrace('action does not exists = ' . $action);
         try {
             $this->render($action);
         } catch (\Exception $e) {
             mdump($e->getMessage() . ' ' . $e->getFile() . ' - ' . $e->getLine());
             throw new ENotFoundException(_M("App: [%s], Module: [%s], Controller: [%s] : action [%s} not found!", [$this->application, $this->module, $this->name, $action]));
         }
     } else {
         try {
             $this->action = $action;
             //if (Manager::getPage()->isPostBack()) {
             //    $actionPost = $action . 'Post';
             //    if (method_exists($this, $actionPost)) {
             //        $action = $actionPost;
             //    }
             //}
             mtrace('executing = ' . $action);
             $method = new \ReflectionMethod(get_class($this), $action);
             $params = $method->getParameters();
             $values = array();
             foreach ($params as $param) {
                 $value = $this->data->{$param->getName()};
                 if (!$value && $param->isDefaultValueAvailable()) {
                     $value = $param->getDefaultValue();
                 }
                 $values[] = $value;
             }
             $result = call_user_func_array([$this, $action], $values);
             if (!$this->getResult()) {
                 if (!Manager::isAjaxCall()) {
                     Manager::$ajax = new \Maestro\UI\MAjax(Manager::getOptions('charset'));
                 }
                 $this->setResult(new Results\MRenderJSON(json_encode($result)));
             }
         } catch (\Exception $e) {
             mdump($e->getMessage());
             if (Manager::PROD()) {
                 $this->renderPrompt('error', $e->getMessage());
             } else {
                 $this->renderPrompt('error', "[<b>" . $this->name . '/' . $action . "</b>]" . $e->getMessage());
             }
         }
     }
 }