function __construct($Request) { $this->_getMethods(); $this->setRequest($Request); $this->setModel(MVC::getModel($Request->get('com'))); $this->setView(new View($this->getModel(), $this->view_path)); }
public static function setController($module, $controller) { $controllerName = ucfirst($controller) . 'Controller'; if (file_exists(APP . DS . 'modules' . DS . $module . DS . 'controllers' . DS . $controllerName . '.php')) { self::$_controller = new $controllerName(self::$_model, self::$_view); } else { header('HTTP/1.0 500 Internal Server Error'); exit("<h1>500 Internal Server Error</h1>Controller could not be found."); } }
public function func() { $model = Model::getModel("User"); if ($model->save($this->input)) { $this->redirect("/foo/login"); return; } else { list($foo, $control, $method) = explode("/", "/foo/bar"); MVC::executeController($control, $method, array(), "/foo/bar", array(), "", array("MVC_CURRENT_MODEL" => $model)); exit; } }
function __construct() { global $Core; $Request = new RequestObject(); $this->com = $Request->get('com'); if (empty($this->com)) { $this->com = 'skin'; $Request->com = 'skin'; } if (!in_array($this->com, $this->valid_coms)) { Core::SBRedirect(SKINNER_URL . "&com=skin"); } $Controller = MVC::getController($Request); $Controller->execute(); $Controller->display(); }
function __construct($type) { $this->dao = MVC::getDAO($type); }
<?php define("WEBROOT", dirname(__FILE__)); define("WEBAPP_ROOT", dirname(__FILE__) . "/../webapp/"); define("LIBS_ROOT", dirname(__FILE__) . "/../libs/"); require_once LIBS_ROOT . "/mvc.php"; // Execute the action MVC::parseRequest();
<?php require_once $_SERVER["DOCUMENT_ROOT"] . '/mvc/lib/mvcroot/php/mvc.class.php'; $mvc = new MVC(); $mvc->controller = isset($_REQUEST['controller']) ? strtolower($_REQUEST['controller']) : 'usuario'; $mvc->action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'Index'; $mvc->Start();
<?php // Options ini_set('display_errors', 1); error_reporting(E_ALL); require_once 'mvc.php'; class Home extends HTMLController { public function index() { return array('clientDetails' => array('uriRequest' => 'http://www.google.com'), 'feature1' => 'Generate mvc.php'); } public function richnote() { return array(); } public function TestPCE($input) { return array('input' => $input); } } MVC::Controller('Home');
function _getPages() { $model = MVC::getModel('page'); $model->index(); return $model->getData(); $dao = new PageDAO(); $dao->index(); return $dao->getData(); }
/** * __construct * @param array $config optional **/ public function __construct($config = array()) { self::$instance = $this; //** Config $this->config = new Config(); if (is_array($config) && count($config)) { while (list($key, $value) = each($config)) { $this->config->set($key, $value); } } //-- End Config if ($this->config->get('path.basepath') == '') { $this->config->set('path.basepath', getcwd() . '/'); } self::$header[] = $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HTTP_RESPONSE[200]; $this->route = new Route(); Route::init(); Route::$BASEPATH = $this->config->get('path.basepath'); $this->url = new Url(Route::$PROTOCOL, Route::$BASEURL, Route::$BASEPATH); $this->assets = new Assets($this->url); $this->request = new Request(); //** ID: Memasukan Libary/Pustaka berdasarkan config | EN: Load Dynamic Libraries from config $libraries = $this->config->get('libraries'); if (is_array($libraries) && count($libraries) > 0) { while (list($library, $params) = each($libraries)) { $clsLibrary = 'Kecik\\' . $library; if (class_exists($clsLibrary)) { if (isset($params['enable']) && $params['enable'] === TRUE) { $library = strtolower($library); //** ID: Untuk Library/Pustaka tanpa parameter //** EN: For Library without parameter if (!isset($params['config']) && !isset($params['params'])) { //** ID: Untuk Library/Pustaka DIC | EN: For DIC Library if ($library == 'dic') { $this->container = new DIC(); } elseif ($library == 'mvc') { if (isset($this->db)) { MVC::setDB($this->db); } } else { // ID: Untuk Library/Pustaka lain | EN: Other Library $this->{$library} = new $clsLibrary(); } //** ID: Untuk Library/Pustaka dengan parameter Kelas Kecik //** EN: For Library with parameter of Kecik CLass } elseif (isset($params['config'])) { //** ID: Buat variabel config //** EN: Create config variable while (list($key, $value) = each($params['config'])) { $this->config->set($library . '.' . $key, $value); } //** ID: untuk Library/Pustaka Database | EN: For Database Library if ($library == 'database') { $this->db = new Database(); if (class_exists('MVC')) { MVC::setDB($this->db); } } else { //** ID: untuk Library/Pustaka lain | EN: For Other library $this->{$library} = new $clsLibrary(); } //** ID: Untuk Library/Pustaka tanpa parameter Kelas Kecik //** EN: For Library without parameter of Kecik CLass } elseif (isset($params['params'])) { $this->{$library} = new $clsLibrary($params['params']); } } } } } //-- ID: Akhir untuk memasukan library/pustaka secara dinamis //-- EN: End Load Dynamic Library spl_autoload_register(array($this, 'autoload'), true, true); }
/** Magic static methods (for db operations) * * @usage * * @todo * check sub classes method */ public static function __callStatic($name, $arguments) { // Call crud methods if (preg_match('/^(Select|Update|Insert|Delete|Count|Increase)([a-zA-Z0-9]+)$/', $name, $matches)) { // db_crud $crud = $matches[1]; $db_crud = 'db_' . strtolower($crud); // convert 'ClassName' to 'class_name' $table = MVC::StrUnderscore($matches[2]); // some action if ($crud == 'Select') { // todo } // add db & table arguments $args = array_merge(array(MVC::$DB, $table), $arguments); return call_user_func_array($db_crud, $args); } else { return FALSE; } }
<?php // Options ini_set('display_errors', 1); error_reporting(E_ALL); require_once 'mvc.php'; require_once 'ViewML.php'; class API extends Controller { public function TestPCE($input) { $pce = PostCompiledExpression::EnforceWhitespace($input->expression); $answer = new PostCompiledExpression($pce, NULL); return array('answer' => $answer->execute()); } public function GenerateMVCDotPHP($req) { } } MVC::Controller('API');
/** * Return an instance of Db Class * If not connection to the database is made then firstly will try to connect to the database * If connection to the database fails then `false` value will be returned * * @return Mixed; */ public function db() { if (!self::$db) { self::$db = new Db($this->config('db')); self::$db->connect(); } return self::$db; }
public static final function executeController($controllerScript, $controllerFunction, $controllerParams, $requestURI, $methodParameters, $queryString, $presetVariables = array()) { // First enable the API, if used if (property_exists('AppConfiguration', 'API')) { if (!empty(AppConfiguration::$API)) { // Include the APIController, which will load itself in the routes as well require_once LIBS_ROOT . "/api.php"; } } // Check routing $routes = array(); if (property_exists('AppConfiguration', 'ROUTES')) { $routes = AppConfiguration::$ROUTES; } if (file_exists(WEBAPP_ROOT . "/tmp/autoroutes.php")) { require_once WEBAPP_ROOT . "/tmp/autoroutes.php"; $routes = array_merge($routes, AutoRoutes::$AUTO_ROUTES); } /** * Check if the request is mapped normally or if we have a routing rule for it */ if (!empty($routes["/{$controllerScript}/{$controllerFunction}"])) { /* Use routing */ $route = $routes["/{$controllerScript}/{$controllerFunction}"]; $controllerFilename = $route["file"]; $controllerClass = $route["class"]; } else { /* Normal mapping */ // Find the controller class $controllerFilename = WEBAPP_ROOT . "/controllers/" . $controllerScript . "_controller.php"; $controllerClass = ucfirst($controllerScript) . "Controller"; } if (!file_exists($controllerFilename)) { controllerErrors::missingcontroller($controllerScript); } require_once $controllerFilename; /* * Populate some variable to the controller */ $controller = new $controllerClass(); $controller->_requestURI = $requestURI; $controller->params = $controllerParams; $controller->controllerName = strtolower($controllerScript); /* Set the controller to the context */ MVCContext::getContext()->setController(&$controller); if (!empty($presetVariables)) { $controller->_contextVariables = $presetVariables; } // Initialize the controller $controller->_init(); /* * See if the requested method exists. If not, we try to find * a method with the name _default to call, which is a "catch-all" -method */ if (!method_exists($controller, $controllerFunction)) { if (!method_exists($controller, "_default")) { controllerErrors::missingMethod($controllerScript, $controllerFunction); } else { $methodParameters = array_merge(array($controllerScript, "default", $controllerFunction), array_slice($methodParameters, 3)); $controllerFunction = "_default"; } } /* * Populate input */ $input = array(); if (!empty($_POST)) { $input = $_POST; $controller->inputmethod = INPUT_METHOD_POST; } else { parse_str($queryString, $input); $controller->inputmethod = INPUT_METHOD_GET; } /* * Begin the execution by processing any filters */ if (property_exists('AppConfiguration', 'FILTERS')) { foreach (AppConfiguration::$FILTERS as $filter) { if ($filter["target"][0] == $controllerScript || $filter["target"][0] == "*") { // Controller -part matches, see if the action matches if ($filter["target"][1] == $controllerFunction || $filter["target"][1] == "*" || is_array($filter["target"][1]) && in_array($controllerFunction, $filter["target"][1])) { // Matches, execute the filter if (!class_exists($filter["filter"])) { require_once WEBAPP_ROOT . "/filters/" . Inflector::decamelize($filter["filter"]) . ".php"; } /* * Invoke the filter. We provide as parameter the controller name, action name and the input * sent from the browser. The input is passed by reference so it can be modified * by the filter along with any parameters defined in the AppConfiguration */ $filterClass = $filter["filter"]; $filterImpl = new $filterClass(); if (call_user_func_array(array($filterImpl, "processFilter"), array($controllerScript, $controllerFunction, $filter["parameters"], &$input)) === false) { // By returning false, the filter can stop the processing // Then we check if we just "die" or do we do some rendering if ($filterImpl->_renderView) { MVC::renderView(!empty($filterImpl->view) ? $filterImpl->view : $controllerFunction, $filterImpl->template, $filterImpl->_contextVariables, $controllerScript, $controllerFunction); } // Exit exit; } } } } } /* * Populate the controller with the input, now that it's been through the filters */ $controller->input = $input; /* * Then continue to the controller */ call_user_func_array(array($controller, $controllerFunction), $methodParameters); /* * Render the view */ if ($controller->_renderView) { /* * Render the view */ MVC::renderView(empty($controller->view) ? $controllerFunction : $controller->view, $controller->template, $controller->_contextVariables, $controllerScript, $controllerFunction); } return $controller; }