KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
controller_deprecated.php
Ir a la documentación de este archivo.
1 <?php
34 {
35 
43  public $models;
51  public $libs;
58  private $_loaded_models = array();
64  public $module_name;
76  public $action_name;
82  public $parameters = array();
89  public $limit_params = TRUE;
95  public $template;
101  public $scaffold;
102 
111  public function __construct($module, $controller, $action, $parameters)
112  {
113  //TODO: enviar un objeto
114  $this->module_name = $module;
115  $this->controller_name = $controller;
116  $this->parameters = $parameters;
117  $this->action_name = $action;
118  //$this->cache['group'] = "$controller.$action";//.$id";
119  //deprecated
120  if ($this->libs) {
121  // Carga las librerias indicadas
122  foreach ($this->libs as $lib) {
123  Load::lib($lib);
124  }
125  }
126 
127  //Carga de modelos
128  if ($this->models) {
129  call_user_func_array(array($this, 'models'), $this->models);
130  }
131  }
132 
138  protected function models($model)
139  {
140  $args = func_get_args();
141  foreach ($args as $model) {
142  $file = APP_PATH . "models/$model.php";
143  if (is_file($file)) {
144  include_once $file;
145  $Model = Util::camelcase(basename($model));
146  $this->$Model = new $Model();
147  $this->_loaded_models[] = $Model;
148  } elseif (is_dir(APP_PATH . "models/$model")) {
149  foreach (new DirectoryIterator(APP_PATH . "models/$model") as $file) {
150  if ($file->isDot() || $file->isDir()) {
151  continue;
152  }
153  if ($file->isFile()) {
154  include_once $file->getPathname();
155  $Model = Util::camelcase(basename($file->getFilename(), '.php'));
156  $this->$Model = new $Model();
157  $this->_loaded_models[] = $Model;
158  }
159  }
160  } else {
161  throw new KumbiaException("Modelo $model no encontrado");
162  }
163  }
164  }
165 
174  protected function cache($time, $type = 'view', $group = FALSE)
175  {
176  View::cache($time, $type, $group);
177  }
178 
189  protected function route_to()
190  {
191  Redirect::route_to(implode(',', func_get_args()));
192  //call_user_func_array(array('Router', 'route_to'), func_get_args());
193  }
194 
201  protected function post($var)
202  {
203  // Si hay mas de un argumento, toma los demas como filtros
204  if (func_num_args() > 1) {
205  return call_user_func_array(array('Request', 'filter'), func_get_args());
206  }
207  return Input::post($var);
208  }
209 
216  protected function get($variable = NULL)
217  {
218  return Input::get($variable);
219  }
220 
227  protected function request($param_name)
228  {
232  $param_name = explode('.', $param_name);
233  if (count($param_name) > 1) {
234  $value = isset($_REQUEST[$param_name[0]][$param_name[1]]) ? $_REQUEST[$param_name[0]][$param_name[1]] : NULL;
235  } else {
236  $value = isset($_REQUEST[$param_name[0]]) ? $_REQUEST[$param_name[0]] : NULL;
237  }
238 
242  if (func_num_args() > 1) {
243  $args = func_get_args();
244  $args[0] = $value;
245 
246  if (is_string($value)) {
247  return call_user_func_array(array('Filter', 'get'), $args);
248  } else {
249  return call_user_func_array(array('Filter', 'get_array'), $args);
250  }
251  }
252  return $value;
253  }
254 
263  protected function has_post($var)
264  {
265  return Input::hasPost($var);
266  }
267 
276  protected function has_get($var)
277  {
278  return Input::hasGet($var);
279  }
280 
289  protected function has_request($var)
290  {
291  return Input::hasRequest($var);
292  }
293 
303  protected function redirect($controller, $seconds=NULL)
304  {
305  Redirect::to($controller, $seconds);
306  }
307 
314  protected function is_ajax()
315  {
316  return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
317  }
318 
326  protected function set_response($type, $template = FALSE)
327  {
328  View::response($type, $template);
329  }
330 
339  protected function render($view, $template = FALSE)
340  {
341  View::select($view, $template);
342  }
343 
349  protected function before_filter()
350  {
351 
352  }
353 
359  protected function after_filter()
360  {
361 
362  }
363 
369  protected function initialize()
370  {
371 
372  }
373 
380  protected function finalize()
381  {
382  //Elimino del controlador los modelos inyectados
383  foreach ($this->_loaded_models as $model) {
384  unset($this->$model);
385  }
386 
387  //Limpia el buffer de modelos inyectados
388  $this->_loaded_models = array();
389 
390  if (isset($this->template)) {
391  View::template($this->template);
392  }
393  //if(isset($this->view)) {
394  // View::select($this->view);
395  //}
396  }
397 
409  protected function set_persistent($var, $value=NULL)
410  {
411  $_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var] = $value;
412  }
413 
425  protected function get_persistent($var)
426  {
427  return $_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var];
428  }
429 
435  protected function destroy_persistent($var)
436  {
437  $args = func_get_args();
438  foreach ($args as $var) {
439  if (isset($_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var])) {
440  unset($_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var]);
441  }
442  }
443  }
444 
451  final public function k_callback($init = FALSE)
452  {
453  if ($init) {
454  if ($this->initialize() !== FALSE) {
455  return $this->before_filter();
456  }
457  return FALSE;
458  }
459 
460  $this->after_filter();
461  $this->finalize();
462  }
463 
464 }