1 <?php
2 3 4 5 6 7
8 namespace Cross\MVC;
9
10 use Cross\Exception\CoreException;
11 use Cross\Core\FrameBase;
12
13 14 15 16 17
18 class Controller extends FrameBase
19 {
20 21 22 23 24
25 protected function is_post()
26 {
27 return $this->delegate->getRequest()->isPostRequest();
28 }
29
30 31 32 33 34
35 protected function is_get()
36 {
37 return $this->delegate->getRequest()->isGetRequest();
38 }
39
40 41 42 43 44
45 protected function is_cli()
46 {
47 return PHP_SAPI === 'cli';
48 }
49
50 51 52 53 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 70 71 72 73 74 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 84 85 86 87
88 protected function redirect($url, $http_response_status = 200)
89 {
90 $this->delegate->getResponse()->redirect($url, $http_response_status);
91 }
92
93 94 95 96 97 98 99 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 111 112 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 144 145 146 147
148 function setAction($action_name)
149 {
150 $this->view->action = $action_name;
151 return $this;
152 }
153 }
154