source: 0.4/forms/controller/application_controller.php @ 3

Revision 3, 7.2 KB checked in by anthemfor182, 6 years ago (diff)

Volviendo a subir la version 0.4

Line 
1<?php
2
3/** KumbiaForms - PHP Rapid Development Framework *****************************
4*       
5* Copyright (C) 2005-2007 Andrés Felipe Gutiérrez (andresfelipe at vagoogle.net)
6*       
7* This framework is free software; you can redistribute it and/or
8* modify it under the terms of the GNU Lesser General Public
9* License as published by the Free Software Foundation; either
10* version 2.1 of the License, or (at your option) any later version.
11*
12* This framework is distributed in the hope that it will be useful,
13* but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15* Lesser General Public License for more details.
16*
17* You should have received a copy of the GNU Lesser General Public
18* License along with this framework; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20*
21* Este framework es software libre; puedes redistribuirlo y/o modificarlo
22* bajo los terminos de la licencia pública general GNU tal y como fue publicada
23* por la Fundación del Software Libre; desde la versión 2.1 o cualquier
24* versión superior.
25*
26* Este framework es distribuido con la esperanza de ser util pero SIN NINGUN
27* TIPO DE GARANTIA; sin dejar atrás su LADO MERCANTIL o PARA FAVORECER ALGUN
28* FIN EN PARTICULAR. Lee la licencia publica general para más detalles.
29*
30* Debes recibir una copia de la Licencia Pública General GNU junto con este
31* framework, si no es asi, escribe a Fundación del Software Libre Inc.,
32* 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
33*
34*************************************************************************/
35
36/**
37 * Es la clase principal para controladores de Kumbia
38 *
39 */
40class ApplicationController extends ApplicationControllerBase  {
41
42        private $cache_view = 0;
43        private $cache_layout = 0;
44        private $cache_template = 0;
45        private $persistance = true;   
46
47        public $response = "";
48        public $controller_name;
49        public $action_name;
50        public $id;
51        static public $force = false;
52
53        /**
54         * Visualiza una vista en el controlador actual
55         *
56         * @param string $view
57         */
58        function render($view){         
59                if(file_exists("views/{$_REQUEST['controller']}/$view.phtml")){
60                        if(is_array(kumbia::$models)){
61                                foreach(kumbia::$models as $model_name => $model){
62                                        $$model_name = $model;
63                                }
64                        }
65                        foreach($this as $var => $value){
66                                $$var = $value;
67                        }                       
68                        include "views/{$_REQUEST['controller']}/$view.phtml";
69                } else {
70                        Flash::kumbia_error('<u>KumbiaError: No existe la Vista</u><br>
71                                                  <span style="font-size:16px">Kumbia no puede encontrar la vista "'.$view.'"
72                                                  </span>');
73                }
74        }
75
76        /**
77         * Redirecciona la ejecución a otro controlador en un
78         * tiempo de ejecución determinado
79         *
80         * @param string $controller
81         * @param integer $seconds
82         */
83        function redirect($controller, $seconds=0.5){
84                $config = Config::read();
85                $seconds*=1000;
86                if(headers_sent()){
87                        print "
88                                <script type='text/javascript'>                                         
89                                        window.setTimeout(\"window.location='".KUMBIA_PATH."$controller'\", $seconds);
90                                </script>\n";                       
91                } else
92                header("Location: ".KUMBIA_PATH."$controller");
93        }
94
95        /**
96         * Visualiza un Texto en la Vista Actual
97         *
98         * @param string $text
99         */
100        function render_text($text){
101                print $text;
102        }
103
104        /**
105         * Visualiza una vista parcial en el controlador actual
106         *
107         * @param string $partial
108         */
109        function render_partial($partial, $values = ''){
110                render_partial($partial, $values);
111        }
112
113        /**
114         * Visualiza una acción ???
115         *
116         * @param string $action
117         */
118        function render_action($action){
119
120        }
121
122        /**
123         * Indica el tipo de Respuesta dada por el controlador
124         *
125         * @param string $type
126         */
127        public function set_response($type){
128                $this->response = $type;
129        }
130
131        /**
132         * Cache la vista correspondiente a la accion durante $minutes
133         *
134         * @param $minutes
135         */
136        public function cache_view($minutes){
137                $this->cache_view = $minutes;
138        }
139
140        /**
141         * Obtiene el valor en minutos para el cache de la
142         * vista actual
143         *
144         */
145        public function get_view_cache(){
146                return $this->cache_view;
147        }
148
149        /**
150         * Cache la vista en views/layouts/
151         * correspondiente al controlador durante $minutes
152         *
153         * @param $minutes
154         */
155        public function cache_layout($minutes){
156                $this->cache_layout = $minutes;
157        }
158
159        /**
160         * Obtiene el valor en minutos para el cache del
161         * layout actual
162         *
163         */
164        public function get_layout_cache(){
165                return $this->cache_layout;
166        }
167
168        /**
169         * Hace el enrutamiento desde un controlador a otro, o desde
170         * una acción a otra.
171         *
172         * Ej:
173         *
174         * return $this->route_to("controller: clientes", "action: consultar", "id: 1");
175         *
176         */
177        public function route_to(){
178                Kumbia::$routed = false;
179                $url = get_params(func_get_args());
180                if($url['controller']){
181                        $_REQUEST['controller'] = $url['controller'];
182                        $_REQUEST['action'] = "index";
183                        Kumbia::$routed = true;
184                }
185                if($url['action']){
186                        $_REQUEST['action'] = $url['action'];
187                        Kumbia::$routed = true;
188                }
189                if($url['id']){
190                        $_REQUEST['id'] = $url['id'];
191                        Kumbia::$routed = true;
192                }
193                return null;
194        }
195
196        /**
197         * Obtiene un valor del arreglo $_POST
198         *
199         * @param string $param_name
200         * @return mixed
201         */
202        public function post($param_name){
203                return $_POST[$param_name];
204        }
205
206        /**
207         * Obtiene un valor del arreglo $_GET
208         *
209         * @param string $param_name
210         * @return mixed
211         */
212        public function get($param_name){
213                return $_GET[$param_name];
214        }
215
216        /**
217         * Obtiene un valor del arreglo $_REQUEST
218         *
219         * @param string $param_name
220         * @return mixed
221         */
222        public function request($param_name){
223                return $_REQUEST[$param_name];
224        }
225
226        /**
227         * Devuelve true si el valor es alpha-numerico
228         *
229         * @param string $value
230         * @return boolean
231         */
232        public function is_alnum($value){
233                return ctype_alnum($value);
234        }
235
236        /**
237         * Devuelve true si el valor es numerico
238         * false en lo contrario
239         *
240         * @param string $value
241         * @return boolean
242         */
243        public function is_numeric($value){
244                return is_numeric($value);
245        }
246
247        /**
248         * Indica si un controlador va a ser persistente, en este
249         * caso los valores internos son automaticamente almacenados
250         * en sesion y disponibles cada vez que se ejecute una acción
251         * en el controlador
252         *
253         * @param boolean $value
254         */
255        public function set_persistance($value){
256
257                $this->persistance = $value;
258
259        }
260
261
262        /**
263         * Sube un archivo al directorio img/upload si esta en $_FILES
264         *
265         * @param string $name
266         * @return string
267         */
268        public function upload_image($name){
269                if($_FILES[$name]){
270                        move_uploaded_file($_FILES[$name]['tmp_name'], htmlspecialchars("public/img/upload/{$_FILES[$name]['name']}"));
271                        return urlencode(htmlspecialchars("upload/".$_FILES[$name]['name']));
272                } else return urlencode($this->request($name));
273        }
274       
275        /**
276         * Sube un archivo al directorio $dir si esta en $_FILES
277         *
278         * @param string $name
279         * @return string
280         */
281        public function upload_file($name, $dir){
282                if($_FILES[$name]){
283                         return move_uploaded_file($_FILES[$name]['tmp_name'], htmlspecialchars("$dir/{$_FILES[$name]['name']}"));                     
284                } else return false;
285        }
286
287}
288
289
290?>
Note: See TracBrowser for help on using the repository browser.