コード例 #1
0
ファイル: Application.php プロジェクト: houzhenggang/cobalt
 /**
  * Allows the application to load a custom or default router.
  *
  * @return  Router
  *
  * @since   1.0
  */
 public function getRouter()
 {
     if (is_null($this->router)) {
         $this->router = new Router($this->input, $this);
         $maps = json_decode(file_get_contents(JPATH_BASE . '/src/routes.json'));
         if (!$maps) {
             throw new \RuntimeException('Invalid router file.');
         }
         $this->router->addMaps($maps, true);
         $this->router->setDefaultController('Cobalt\\Controller\\DefaultController');
     }
     return $this->router;
 }
コード例 #2
0
ファイル: Save.php プロジェクト: houzhenggang/cobalt
 public function execute()
 {
     $modelName = ucwords($this->getInput()->get('model'));
     $modelPath = "Cobalt\\Model\\" . $modelName;
     $model = new $modelPath();
     $view = $this->getInput()->get('view');
     $response = new \stdClass();
     $link = $this->getInput()->get('return', Router::to('index.php?view=' . $view));
     if ($itemId = $model->store()) {
         $msg = TextHelper::_('COBALT_SUCCESSFULLY_SAVED');
         $getItem = 'get' . $modelName;
         if ($this->isAjaxRequest()) {
             $response->item = $model->{$getItem}($itemId);
             $response->alert = new \stdClass();
             $response->alert->message = $msg;
             $response->alert->type = 'success';
             // just send reload page if send refresh_page=1
             if ($this->getInput()->getInt('refresh_page', 0)) {
                 $response->reload = '3000';
             }
             $this->getApplication()->close(json_encode($response));
         } else {
             $this->getApplication()->redirect($link, $msg);
         }
     } else {
         $msg = TextHelper::_('COBALT_ERROR_SAVING');
         if ($this->isAjaxRequest()) {
             $this->getApplication()->redirect($link, $msg);
         } else {
             $response->alert = new \stdClass();
             $response->alert->message = $msg;
             $response->alert->type = 'danger';
             $this->getApplication()->close(json_encode($response));
         }
     }
 }