KumbiaPHP beta2-dev
Framework PHP en español
controller_deprecated.php
Ir a la documentación de este archivo.
00001 <?php
00024 class ControllerDeprecated
00025 {
00033         public $models;
00041         public $libs;
00042 
00049         private $_loaded_models = array();
00050 
00056         public $module_name;
00062         public $controller_name;
00068         public $action_name;
00075         public $limit_params = TRUE;
00081         public $scaffold;
00090         public function __construct($module, $controller, $action, $parameters)
00091         {
00092                 //TODO: enviar un objeto
00093                 $this->module_name = $module;
00094                 $this->controller_name = $controller;
00095                 $this->parameters = $parameters;
00096                 $this->action_name = $action;
00097         //$this->cache['group'] = "$controller.$action";//.$id";
00098 
00099                 //deprecated
00100                 if($this->libs) {
00101                         // Carga las librerias indicadas
00102                         foreach($this->libs as $lib) {
00103                                 Load::lib($lib);
00104                         }
00105                 }
00106 
00107                 //Carga de modelos
00108                 if($this->models) {
00109                         call_user_func_array(array($this, 'models'), $this->models);
00110                 }
00111         }
00112 
00118         protected function models ($model)
00119     {
00120                 $args = func_get_args();
00121         foreach ($args as $model) {
00122             $file = APP_PATH . "models/$model.php";
00123             if (is_file($file)) {
00124                 include_once $file;
00125                 $Model = Util::camelcase(basename($model));
00126                 $this->$Model = new $Model();
00127                 $this->_loaded_models[] = $Model;
00128             } elseif (is_dir(APP_PATH . "models/$model")) {
00129                                 foreach (new DirectoryIterator(APP_PATH . "models/$model") as $file) {
00130                                         if ($file->isDot() || $file->isDir()) {
00131                                                 continue;
00132                                         }
00133                                         if ($file->isFile()) {
00134                                                 include_once $file->getPathname();
00135                                                 $Model = Util::camelcase(basename($file->getFilename(), '.php'));
00136                                                 $this->$Model = new $Model();
00137                                                 $this->_loaded_models[] = $Model;
00138                                         }
00139                                 }
00140             } else {
00141                 throw new KumbiaException("Modelo $model no encontrado");
00142             }
00143         }
00144     }
00153         protected function cache($time, $type = 'view', $group = FALSE)
00154         {
00155                 View::cache($time, $type, $group);
00156         }
00167         protected function route_to()
00168         {
00169                 Router::route_to(implode(',', func_get_args()));
00170                 //call_user_func_array(array('Router', 'route_to'), func_get_args());
00171         }
00172 
00179         protected function post($var)
00180         {
00181                  // Si hay mas de un argumento, toma los demas como filtros
00182                 if(func_num_args()>1){
00183                         return call_user_func_array(array('Request', 'filter'), func_get_args());
00184                 }
00185                 return Input::post($var);
00186         }
00187 
00194         protected function get($variable = NULL)
00195         {       //FILTER_SANITIZE_STRING
00196                 if($variable){
00197 
00198                 } else {
00199                         $value = filter_input_array (INPUT_GET, FILTER_SANITIZE_STRING);
00200                 }
00201                 //$value = filter_has_var(INPUT_GET, $variable) ? $_GET[$variable] : NULL;
00202 
00206                 if(func_num_args()>1){
00207                         $args = func_get_args();
00208                         $args[0] = $value;
00209 
00210             if(is_string($value)) {
00211                 return call_user_func_array(array('Filter', 'get'), $args);
00212             } else {
00213                 return call_user_func_array(array('Filter', 'get_array'), $args);
00214             }
00215                 }
00216                 return Input::get($variable);
00217         }
00218 
00225         protected function request($param_name)
00226     {
00230                 $param_name = explode('.', $param_name);
00231                 if(count($param_name)>1) {
00232                         $value = isset($_REQUEST[$param_name[0]][$param_name[1]]) ? $_REQUEST[$param_name[0]][$param_name[1]] : NULL;
00233                 } else {
00234                         $value = isset($_REQUEST[$param_name[0]]) ? $_REQUEST[$param_name[0]] : NULL;
00235                 }
00236 
00240                 if(func_num_args()>1){
00241                         $args = func_get_args();
00242                         $args[0] = $value;
00243 
00244             if(is_string($value)) {
00245                 return call_user_func_array(array('Filter', 'get'), $args);
00246             } else {
00247                 return call_user_func_array(array('Filter', 'get_array'), $args);
00248             }
00249                 }
00250                 return $value;
00251         }
00252 
00261         protected function has_post($var)
00262         {
00263                 return Input::hasPost($var);
00264         }
00265 
00274         protected function has_get($var)
00275         {
00276                 return Input::hasGet($var);
00277         }
00278 
00288         protected function has_request($var)
00289         {
00290                 return Input::hasRequest($var);
00291         }
00292 
00302         protected function redirect($controller, $seconds=NULL)
00303         {
00304                 Router::redirect($controller,$seconds);
00305         }
00306 
00313         protected function is_ajax()
00314         {
00315                 return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
00316         }
00317 
00325         protected function set_response($type, $template = FALSE)
00326         {
00327                 View::response($type, $template);
00328         }
00329 
00338         protected function render($view,$template = FALSE){
00339                 View::select($view, $template);
00340         }
00346     protected function before_filter()
00347     {
00348     }
00354     protected function after_filter()
00355     {
00356     }
00362     protected function initialize()
00363     {
00364     }
00371     protected function finalize()
00372     {
00373                 //Elimino del controlador los modelos inyectados
00374                 foreach ($this->_loaded_models as $model) {
00375                         unset($this->$model);
00376                 }
00377 
00378                 //Limpia el buffer de modelos inyectados
00379                 $this->_loaded_models = array();
00380                 
00381                 if(isset($this->template)) {
00382                         View::template($this->template);
00383                 }
00384                 //if(isset($this->view)) {
00385                 //      View::select($this->view);
00386                 //}
00387     }
00399         protected function set_persistent($var, $value=NULL)
00400         {
00401                 $_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var] = $value;
00402 
00403         }
00415         protected function get_persistent($var)
00416         {
00417                 return $_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var];
00418     }
00419 
00425         protected function destroy_persistent($var)
00426         {
00427             $args = func_get_args();
00428             foreach ($args as $var) {
00429             if(isset($_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var])) {
00430                 unset($_SESSION['KUMBIA_CONTROLLER']["$this->module_name/$this->controller_name"][$var]);
00431             }
00432             }
00433         }
00440     final public function k_callback($init = FALSE)
00441     { 
00442         if($init){
00443                         if($this->initialize() !== FALSE){
00444                                 return $this->before_filter();
00445                         }
00446                         return FALSE;
00447                 }
00448         
00449                 $this->after_filter();
00450                 $this->finalize();
00451     }
00452 }
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Enumeraciones