Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/05/2011, 13:31
Hidek1
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
Respuesta: Hola amigos me estoy iniciando en el modelo vista controlador y me ha surg

pues es básicamente eso... ahí cada vez vas implementando mejoras o diferentes ideas dependiendo de lo que necesites.

te dejo mi controller por si te sirve para sacar alguna duda.


saludos.


Código PHP:
<?php
/**
 * Khaus Framework
 *
 * LICENSE
 *
 * This source file is subject to the Public license Creative Commons LPCC
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * [url]http://creativecommons.org/licenses/by-nc/2.0/cl/[/url]
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email][email protected][/email] so we can send you a copy immediately.
 *
 * @category    Khaus
 * @package     Khaus
 * @copyright   Copyright (c) 2010 - 2011, Khaus Corp. Chile [[email protected]]
 * @license     Atribución-Licenciar Igual 2.0 Chile. CC BY-NC 2.0
 * @version     6:20110121
 */

class Khaus_Controller
{
    protected 
$_className;
    protected 
$_methodName;

    public function 
__construct()
    {
        
$request = new Khaus_Controller_Request();
        
$request $request->getRequest();
        
$this->_className $this->_getClassName($request[0]);
        
$this->_methodName $this->_getMethodName($request[1]);
        
$this->_makeResponse();
    }

    private function 
_makeResponse()
    {
        
$className $this->_className;
        
$methodName $this->_methodName;
        
// construyo la ruta donde deberia estar la class
        
$classLocation APPLICATION_PATH '/controllers/' $className '.php';
        
        
// si la class existe
        
if (is_file($classLocation)) {
            require_once 
$classLocation;
            
            
// registro los nombres de class y method
            
Khaus_Pattern_Registry::add('className'$className);
            
Khaus_Pattern_Registry::add('methodName'$methodName);
            
            if (
method_exists($className$methodName)) { // si la accion existe.. (metodo)
                
$class = new $className// instancio la class
                
$class->$methodName(); // ejecuto el metodo
                
$this->_response $class->templateRender(); // obtengo el template procesado
            
} else {
                throw new 
Khaus_Exception("Metodo $methodName no existe"404);
            }
        } else {
            throw new 
Khaus_Exception("$className no encontrado"404);
        }
    }

    public function 
getResponse()
    {
        return 
$this->_response;
    }

    private function 
_getClassName($request)
    {
        if (empty(
$request)) {
            
$request 'index';
        }
        return 
ucfirst($request) . 'Controller';
    }
    
    public function 
_getMethodName($request)
    {
        if (empty(
$request)) {
            
$request $this->_className;
            
$request str_replace('Controller'''$request);
        }
        return 
strtolower($request) . 'Action';
    }
}
__________________
More about me...
~ @rhyudek1
~ Github