public function index(Request $request)
 {
     $newsModel = new Models\NewsModel();
     $onPage = 10;
     $page = intval($request->get('page'));
     $news = $newsModel->select($page, $onPage);
     $response = new Response();
     $response->header('Content-type', 'application/json')->content(json_encode(['method' => 'newslist', 'result' => ['items' => $news, 'total' => 12, 'page' => $page, 'onpage' => $onPage, 'pages' => 2]]));
     return $response;
 }
Example #2
0
 public function getURL($params, $clean = true)
 {
     $request = \Core\Http\Request::getInstance();
     if ($clean) {
         $params = array_merge(array('module' => $request->getModule(), 'controller' => $request->getController(), 'action' => $request->getAction()), $params);
     } else {
         $p = $request->getParams();
         $names = array_keys($_POST);
         foreach ($p as $n => $v) {
             if (in_array($n, $names)) {
                 unset($p[$n]);
             }
         }
         $params = array_merge(array('module' => $request->getModule(), 'controller' => $request->getController(), 'action' => $request->getAction()), $p, $params);
     }
     $module = $params['module'];
     $controller = $params['controller'];
     $action = $params['action'];
     unset($params['module']);
     unset($params['controller']);
     unset($params['action']);
     $uri = \Core\Config::getInstance()->app['baseUrl'] . $module . '/' . $controller . '/' . $action . '/';
     if (!empty($params)) {
         $ps = array_keys($params);
         foreach ($ps as $param) {
             if ($param == session_name()) {
                 continue;
             }
             if (!is_null($params[$param])) {
                 $uri .= $param . '/' . $params[$param] . '/';
             }
         }
     }
     return $uri;
 }
Example #3
0
 public function issetFilter($name)
 {
     if (\Core\Http\Request::getInstance()->isPost()) {
         if (isset($_REQUEST[$name]) && empty($_REQUEST[$name])) {
             unset($this->_storage[$name]);
         }
     }
     return !empty($this->_storage[$name]);
 }
Example #4
0
 /**
  * Dispatch
  * @return string
  */
 public function dispatch()
 {
     $this->_requestURI = str_replace($this->_baseUrl, '', $this->_requestURI);
     $uri = explode('/', trim($this->_requestURI, '/'));
     $i = 0;
     $mvcData = array();
     while ($i < 3) {
         $tmp = array_shift($uri);
         switch ($i) {
             case 0:
                 $mvcData['module'] = empty($tmp) ? 'main' : $tmp;
                 break;
             case 1:
                 $mvcData['controller'] = empty($tmp) ? 'index' : $tmp;
                 break;
             case 2:
                 $mvcData['action'] = empty($tmp) ? 'index' : $tmp;
                 break;
         }
         $i++;
     }
     if (!$this->_isDispatchable($mvcData)) {
         $mvcData = array('module' => 'main', 'controller' => 'error', 'action' => 'notfound');
     } elseif (!$this->_isAclAllow($mvcData)) {
         if (\Core\Auth\Auth::getInstance()->hasIdentity()) {
             $mvcData = array('module' => 'main', 'controller' => 'error', 'action' => 'accessdenied');
         } else {
             $mvcData = array('module' => 'main', 'controller' => 'user', 'action' => 'login');
         }
     }
     $request = \Core\Http\Request::getInstance();
     while (!empty($uri)) {
         $param = array_shift($uri);
         $value = array_shift($uri);
         $request->setParam($param, $value);
     }
     $request->setModule($mvcData['module'])->setController($mvcData['controller'])->setAction($mvcData['action']);
     $loader = \Core\Loader::getInstance();
     $response = $loader->runController($mvcData);
     if ($loader->needRenderLayout) {
         $config = \Core\Config::getInstance();
         if (!empty($config->layout[$mvcData['module']])) {
             $layout_script = APP_PATH . 'layouts/' . $config->layout[$mvcData['module']] . '.phtml';
         } else {
             $layout_script = APP_PATH . 'layouts/main.phtml';
         }
         $layout = new \Core\View\Layout();
         $layout->setContent($response);
         return $layout->render($layout_script);
     } else {
         return $response;
     }
 }
Example #5
0
 public function render($content)
 {
     if ($this->getOption('sortable')) {
         $fieldName = $this->getOption('currentField');
         $request = \Core\Http\Request::getInstance();
         $sortby = $request->getParam('sortby', false);
         $img = '';
         if ($sortby == $fieldName) {
             $sort = $request->getParam('sortorder', false);
             $img = '<img class="fv_sort_order" src="' . \Core\Config::getInstance()->app['baseUrl'] . 'i/s_' . $sort . '.png" alt="sort" />';
         } else {
             $sort = false;
         }
         $sort = $sort == false || $sort == 'desc' ? 'asc' : 'desc';
         $url = $this->getDecorator()->view->_helperUrl->getUrl(array('sortby' => $fieldName, 'sortorder' => $sort), false);
         $decorator = new \Core\Grid\Decorator\HtmlTag(array('tag' => 'a', 'attrs' => array('href' => $url)));
         $content .= $img;
         $content = $decorator->render($content);
     }
     return parent::render($content);
 }
Example #6
0
 public function script($name)
 {
     $request = \Core\Http\Request::getInstance();
     $view_script = APP_PATH . 'modules/' . $request->getModule() . '/views/' . $request->getController() . '/' . $name . '.phtml';
     return $this->_view->render($view_script);
 }
Example #7
0
 protected function _applyOrder()
 {
     $request = \Core\Http\Request::getInstance();
     $sortby = $request->getParam('sortby', false);
     $sortorder = $request->getParam('sortorder', false);
     if ($sortby && $sortorder) {
         $this->_model->setOrder($sortby . ' ' . $sortorder);
     }
 }
Example #8
0
 /**
  * Get request param
  * @param string $name
  * @param mixed $default
  * @return mixed
  */
 protected function _getParam($name, $default = false)
 {
     return $this->_request->getParam($name, $default);
 }
Example #9
0
 public function setRequest(Request $request)
 {
     $this->request = $request;
     $this->requestUri = $this->clearPath($request->getRequestUri());
     $this->requestMethod = $request->getMethod();
 }
Example #10
0
 /**
  * 获取请求的主机名
  */
 public function getHost()
 {
     return $this->request->getHostName();
 }