CrossPHP
  • Namespace
  • Class
  • Download

Namespaces

  • Cross
    • Auth
    • Cache
      • Driver
      • Request
    • Core
    • DB
      • Connecter
      • Drivers
      • SQLAssembler
    • Exception
    • Http
    • I
    • Lib
      • Document
    • Module
    • MVC
    • Runtime
  • None

Classes

  • Cross\Auth\CookieAuth
  • Cross\Auth\SessionAuth
  • Cross\Cache\Driver\FileCacheDriver
  • Cross\Cache\Driver\MemcacheDriver
  • Cross\Cache\Driver\RedisDriver
  • Cross\Cache\Request\FileCache
  • Cross\Cache\Request\Memcache
  • Cross\Cache\Request\RedisCache
  • Cross\Cache\RequestCache
  • Cross\Core\Annotate
  • Cross\Core\Application
  • Cross\Core\ArrayMap
  • Cross\Core\Config
  • Cross\Core\CrossArray
  • Cross\Core\Delegate
  • Cross\Core\FrameBase
  • Cross\Core\Helper
  • Cross\Core\HttpAuth
  • Cross\Core\Loader
  • Cross\Core\Rest
  • Cross\Core\Router
  • Cross\DB\Connecter\BaseConnecter
  • Cross\DB\Connecter\MySQLConnecter
  • Cross\DB\Connecter\PgSQLConnecter
  • Cross\DB\Connecter\SQLiteConnecter
  • Cross\DB\DBFactory
  • Cross\DB\Drivers\CouchDriver
  • Cross\DB\Drivers\MongoDriver
  • Cross\DB\Drivers\PDOSqlDriver
  • Cross\DB\SQLAssembler\MySQLAssembler
  • Cross\DB\SQLAssembler\PgSQLAssembler
  • Cross\DB\SQLAssembler\SQLAssembler
  • Cross\DB\SQLAssembler\SQLiteAssembler
  • Cross\Http\Request
  • Cross\Http\Response
  • Cross\Lib\Array2XML
  • Cross\Lib\Document\CallTree
  • Cross\Lib\Document\CallTreeToHTML
  • Cross\Lib\Document\HTML
  • Cross\Lib\StringToPHPStream
  • Cross\Module\SQLModule
  • Cross\MVC\Controller
  • Cross\MVC\Module
  • Cross\MVC\View
  • Cross\Runtime\ClosureContainer

Interfaces

  • Cross\I\CacheInterface
  • Cross\I\HttpAuthInterface
  • Cross\I\PDOConnecter
  • Cross\I\RequestCacheInterface
  • Cross\I\RouterInterface
  • Cross\I\SqlInterface

Exceptions

  • Cross\Exception\CacheException
  • Cross\Exception\CoreException
  • Cross\Exception\CrossException
  • Cross\Exception\FrontException

Functions

  • ascLogo
  • line
  • tBody
  • th
  • tHead
  1 <?php
  2 /**
  3  * Cross - a micro PHP 5 framework
  4  *
  5  * @link        http://www.crossphp.com
  6  * @license     MIT License
  7  */
  8 namespace Cross\MVC;
  9 
 10 use Cross\Exception\CoreException;
 11 use Cross\Core\FrameBase;
 12 
 13 /**
 14  * @author wonli <wonli@live.com>
 15  * Class Controller
 16  * @package Cross\MVC
 17  */
 18 class Controller extends FrameBase
 19 {
 20     /**
 21      * 判断一个链接是否为post请求
 22      *
 23      * @return boolean
 24      */
 25     protected function is_post()
 26     {
 27         return $this->delegate->getRequest()->isPostRequest();
 28     }
 29 
 30     /**
 31      * 判断请求类型是否为get
 32      *
 33      * @return bool
 34      */
 35     protected function is_get()
 36     {
 37         return $this->delegate->getRequest()->isGetRequest();
 38     }
 39 
 40     /**
 41      * 是否cli方式发起请求
 42      *
 43      * @return bool
 44      */
 45     protected function is_cli()
 46     {
 47         return PHP_SAPI === 'cli';
 48     }
 49 
 50     /**
 51      * 判断是否为一个ajax请求
 52      *
 53      * @return boolean
 54      */
 55     protected function is_ajax_request()
 56     {
 57         return $this->delegate->getRequest()->isAjaxRequest();
 58     }
 59 
 60     /**
 61      * 返回执行的前一页
 62      */
 63     protected function return_referer()
 64     {
 65         $this->redirect($this->request->getUrlReferrer());
 66     }
 67 
 68     /**
 69      * 先生成连接再redirect
 70      *
 71      * @param string|null $controller controller:action
 72      * @param string|array $params
 73      * @param bool $sec
 74      * @throws CoreException
 75      */
 76     protected function to($controller = null, $params = null, $sec = false)
 77     {
 78         $url = $this->view->url($controller, $params, $sec);
 79         $this->redirect($url);
 80     }
 81 
 82     /**
 83      * @see Response::redirect
 84      *
 85      * @param string $url
 86      * @param int $http_response_status
 87      */
 88     protected function redirect($url, $http_response_status = 200)
 89     {
 90         $this->delegate->getResponse()->redirect($url, $http_response_status);
 91     }
 92 
 93     /**
 94      * @see View::display()
 95      *
 96      * @param null|mixed $data
 97      * @param null|string $method
 98      * @param int $http_response_status
 99      * @throws CoreException
100      */
101     protected function display($data = null, $method = null, $http_response_status = 200)
102     {
103         $this->delegate->getResponse()->setResponseStatus($http_response_status);
104         $this->view->display($data, $method);
105     }
106 
107     /**
108      * 发送一个包含文件名的下载头
109      *
110      * @param null $file_name
111      * @param array $add_header
112      * @param bool $only_add_header
113      */
114     protected function sendDownloadHeader($file_name = null, $add_header = array(), $only_add_header = false)
115     {
116         if (null === $file_name) {
117             $file_name = $this->controller . '_' . $this->action;
118         }
119 
120         $download_header = array(
121             "Pragma: public",
122             "Expires: 0",
123             "Cache-Control: must-revalidate, post-check=0, pre-check=0",
124             "Content-Type: application/force-download",
125             "Content-Type: application/octet-stream",
126             "Content-Type: application/download",
127             "Content-Disposition:attachment;filename={$file_name}",
128             "Content-Transfer-Encoding:binary"
129         );
130 
131         if (!empty($add_header)) {
132             if (true === $only_add_header) {
133                 $download_header = $add_header;
134             } else {
135                 $download_header = array_merge($download_header, $add_header);
136             }
137         }
138 
139         $this->delegate->getResponse()->setHeader($download_header);
140     }
141 
142     /**
143      * 重设视图action名称
144      *
145      * @param $action_name
146      * @return $this
147      */
148     function setAction($action_name)
149     {
150         $this->view->action = $action_name;
151         return $this;
152     }
153 }
154 
CrossPHP API documentation generated by ApiGen