Slimore
  • Namespace
  • Class

Namespaces

  • None
  • Slimore
    • Cache
      • Exception
    • Captcha
    • Database
    • Debug
    • Http
    • Image
    • Log
    • Middleware
    • Mvc
    • Pagination
    • Upload

Classes

  • Slimore\Cache\File
  • Slimore\Captcha\Builder
  • Slimore\Database\Manager
  • Slimore\Debug\Simpler
  • Slimore\Http\Client
  • Slimore\Image\Gd
  • Slimore\Log\Writer
  • Slimore\Middleware\Exceptions
  • Slimore\Mvc\Application
  • Slimore\Mvc\Controller
  • Slimore\Mvc\Model
  • Slimore\Mvc\View
  • Slimore\Pagination\Paginator
  • Slimore\Upload\Uploader

Exceptions

  • Slimore\Cache\Exception\File
  • Slimore\Captcha\Exception
  • Slimore\Database\Exception
  • Slimore\Http\Exception
  • Slimore\Mvc\Exception
  • Slimore\Pagination\Exception
  • Slimore\Upload\Exception

Functions

  • arrayToObject
  • console
  • controller
  • ctl
  • currentUrl
  • decrypt
  • detectDevice
  • encrypt
  • fileFormatSize
  • getDirectoryItems
  • getDpi
  • hexToRGB
  • html
  • imageDataUrl
  • iPad
  • iPhone
  • iPod
  • isAndroid
  • isApache
  • isBlackberry
  • isChrome
  • isCli
  • isFirefox
  • isFreeBSD
  • isIE
  • isIIS
  • isJson
  • isLinux
  • isMacOSX
  • isMobile
  • isNginx
  • isOpera
  • isSafari
  • isTablet
  • isUnix
  • isUnixLike
  • isWebOS
  • isWindows
  • js
  • jsonToArray
  • linkTag
  • password
  • phoneMaskCode
  • randomCharacters
  • replaceDirSeparator
  • rgbToHex
  • script
  • shortUrl
  • style
  1 <?php
  2 
  3 /**
  4  * Slimore - The fully (H)MVC framework based on the Slim PHP framework.
  5  *
  6  * @author      Pandao <slimore@ipandao.com>
  7  * @copyright   2015 Pandao
  8  * @link        http://github.com/slimore/slimore
  9  * @license     MIT License https://github.com/slimore/slimore#license
 10  * @version     0.1.0
 11  * @package     Slimore\Mvc
 12  */
 13 
 14 namespace Slimore\Mvc;
 15 
 16 use \Slimore\Debug           as Debug;
 17 use \Slimore\Mvc\Application as Application;
 18 
 19 /**
 20  * Class Controller
 21  *
 22  * @author  Pandao
 23  * @package Slimore\Mvc
 24  */
 25 
 26 class Controller
 27 {
 28     /**
 29      * @var \Slim\Slim
 30      */
 31 
 32     protected $app;
 33 
 34     /**
 35      * @var mixed
 36      */
 37 
 38     protected $db;
 39 
 40     /**
 41      * @var mixed
 42      */
 43 
 44     protected $log;
 45 
 46     /**
 47      * @var string
 48      */
 49 
 50     protected $viewPath   = '../app/views/';
 51 
 52     /**
 53      * @var string
 54      */
 55 
 56     protected $viewSuffix = '.php';
 57 
 58     /**
 59      * Constructor
 60      */
 61 
 62     public function __construct()
 63     {
 64         $this->app = Application::getInstance();
 65         $this->db  = $this->app->db;
 66         $this->log = $this->app->log;
 67 
 68         $this->setViewPath($this->app->path . $this->moduleName . DIRECTORY_SEPARATOR . 'views');
 69 
 70         $this->init();
 71     }
 72 
 73     /**
 74      * Initialization (supplementary) method
 75      *
 76      * @return void
 77      */
 78 
 79     protected function init()
 80     {
 81     }
 82 
 83     /**
 84      * @param string $name null
 85      * @return mixed
 86      */
 87 
 88     protected function dbConnection($name = null)
 89     {
 90         return $this->db->getConnection($name);
 91     }
 92 
 93     /**
 94      * @param array $array
 95      * @param bool $return false
 96      * @return string
 97      */
 98 
 99     public function json(array $array, $return = false)
100     {
101         $this->response->header('Content-Type', 'application/json');
102         $this->response->status(200);
103 
104         $jsonpCallback = $this->app->request->get('callback', null);
105 
106         $json = ($jsonpCallback !== null) ? $jsonpCallback . '('.json_encode($array).')' : json_encode($array);
107 
108         if ($return) return $json;
109         else         echo   $json;
110     }
111 
112     /**
113      * Using javascript
114      *
115      * @param string|array $script
116      * @param bool $wrap false
117      * @return string
118      */
119 
120     public function js($script, $wrap = false)
121     {
122         Debug::js($script, $wrap);
123     }
124 
125     /**
126      * Alias js() method
127      *
128      * @param string|array $script
129      * @param bool $wrap false
130      * @return string
131      */
132 
133     public function javascript($script, $wrap = false)
134     {
135         Debug::js($script, $wrap);
136     }
137 
138     /**
139      * Using pre format tag formatted printing array
140      *
141      * @param mixed $array
142      * @return void
143      */
144 
145     public function printr($array)
146     {
147         Debug::printr($array);
148     }
149 
150     /**
151      * Like/Using javascript console object
152      *
153      * @param string $message
154      * @param string $type "log"
155      * @return string
156      */
157 
158     public function console($message, $type = "log")
159     {
160         Debug::console($message, $type);
161     }
162 
163     /**
164      * Using javascript location.href go to url
165      *
166      * @param string $url
167      * @param bool $base true
168      * @return string
169      */
170 
171     public function gotoURL($url, $base = true)
172     {
173         if ($base) {
174             $url = $this->app->baseURL . $url;
175         }
176 
177         $this->js('location.href="'.$url.'";');
178     }
179 
180     /**
181      * Application (re)configure
182      *
183      * @param string $name
184      * @return mixed
185      */
186 
187     protected function config($name)
188     {
189         return $this->app->config($name);
190     }
191 
192     /**
193      * Redirect controller
194      *
195      * @param string $path
196      * @return void
197      */
198 
199     protected function redirect($path)
200     {
201         $path = str_replace('//', '/', $this->app->baseURL . $path);
202 
203         $this->app->redirect($path);
204     }
205 
206     /**
207      * Override \Slim\Slim::render method on controller
208      *
209      * @param string $tpl
210      * @param array $data []
211      * @param string $suffix
212      * @return void
213      */
214 
215     protected function render($tpl, array $data = [])
216     {
217         $suffix = $this->app->config('template.suffix');
218         $suffix = (empty($suffix)) ? $this->viewSuffix : $suffix;
219         $tpl   .= $suffix;
220 
221         $this->app->render($tpl, $data);
222     }
223 
224     /**
225      * Set view path
226      *
227      * @param string $path
228      */
229 
230     protected function setViewPath($path)
231     {
232         $this->view->setTemplatesDirectory($path);
233     }
234 
235     /**
236      * Get view path
237      *
238      * @return string
239      */
240 
241     protected function getViewPath()
242     {
243         return $this->view->getTemplatesDirectory();
244     }
245 
246     /**
247      * Getter
248      *
249      * @param $name
250      * @return mixed
251      */
252 
253     public function __get($name)
254     {
255         if ( property_exists ($this->app, $name ) || method_exists ($this->app, $name ))
256         {
257             return  $this->app->$name;
258         }
259     }
260 
261     /**
262      * Member method overloading
263      *
264      * @param $method
265      * @param $args
266      * @return mixed
267      */
268 
269     public function __call($method, $args)
270     {
271         if ( method_exists ($this->app, $method ))
272         {
273             return $this->app->$method($args);
274         }
275     }
276 
277     /**
278      * Static member method overloading
279      *
280      * @param $method
281      * @param $args
282      * @return mixed
283      */
284 
285     public static function __callStatic($method, $args)
286     {
287         $app = self::$app;
288 
289         if ( method_exists ($app, $method ))
290         {
291             return $app::$method($args);
292         }
293     }
294 }
Slimore API documentation generated by ApiGen