本文整理汇总了PHP中Router::getController方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getController方法的具体用法?PHP Router::getController怎么用?PHP Router::getController使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::getController方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$suffix = "Controller";
Router::parseUri();
try {
$_cc = ucfirst(Router::getController()) . $suffix;
Loader::autoload($_cc);
if (!class_exists($_cc, false) && !interface_exists($_cc, false)) {
throw new Exception('Class ' . $_cc . ' does not exist');
}
$class = new ReflectionClass($_cc);
if ($class->isAbstract()) {
throw new Exception('Cannot create instances of abstract ' . $_cc . '');
}
// Create a new instance of the controller
$controller = $class->newInstance();
// Execute the "before action" method
//$class->getMethod('before')->invoke($controller);
// Execute the main action with the parameters
$class->getMethod(Router::getAction() . 'Action')->invokeArgs($controller, Router::getParams());
// Execute the "after action" method
//$class->getMethod('after')->invoke($controller);
} catch (Exception $e) {
throw $e;
}
return $this;
}
示例2: run
/**
* This method launches the application.
*/
public function run()
{
$router = new Router($this);
$controller = $router->getController();
$controller->execute();
$this->response->setPage($controller->getPage());
$this->response->send();
}
示例3: init
/**
* 初始化
*
*/
public function init()
{
$this->set('currentUrl', Request::currentUrl());
$this->set('refererUrl', Request::refererUrl());
$this->set('controller', Router::getController());
$this->set('action', Router::getAction());
$this->set('get', Request::getGet());
$this->set('post', Request::getPost());
}
示例4: dispatch
public static function dispatch(Router $router)
{
// ob_start();
$className = ucfirst($router->getController()) . 'Controller';
$actionName = $router->getAction() . 'Action';
$controllerFile = CONTROLLER_DIR . '/' . $className . '.class.php';
if (file_exists($controllerFile)) {
include_once $controllerFile;
$app = new $className($router->getParams(), $router->getController());
$app->{$actionName}();
// $output = ob_get_clean();
// echo $output;
} else {
// throw new Exception('Controller not found. className:['.$className.']');
Log::fatal('Controller not found. className:[%s]', var_export($className, 1));
trigger_error('Controller not found. className:[' . var_export($className, 1) . ']', E_USER_ERROR);
}
}
示例5: file_path
private function file_path($tpl = null)
{
$tplDir = Router::getController();
$tplName = isset($tpl) ? $tpl : Router::getAction();
$templateFile = VIEW_DIR . $tplDir . DS . $tplName . '.phtml';
if (!file_exists($templateFile)) {
throw new Exception("{$templateFile} not found", 404);
}
return $templateFile;
}
示例6: __construct
public function __construct()
{
$this->controller = Router::getController();
// get current controller
$this->action = Router::getAction();
// get current action/method
// check if there is an ID on current route (URL)
if (Router::hasID()) {
$this->id = Router::getID();
// get ID
}
}
示例7: _call
protected final function _call($path, $args = array())
{
$parts = explode('/', $path);
if ($parts[0] == '') {
array_shift($parts);
}
$router = new Router();
$controller = $router->getController(new Context('controller', $parts[0], $parts[1], $args));
if ($controller) {
return $controller->_execute(false);
}
return false;
}
示例8: run
public function run()
{
if (Tipkin\Config::get('maintenance-mode') == 'on') {
$this->httpResponse->redirect('/maintenance.html');
exit;
}
$router = new Router($this);
$controller = $router->getController();
if (!is_null($controller)) {
$controller->execute();
$this->httpResponse->setPage($controller->page());
}
}
示例9: run
public function run()
{
if ($this->user->isAdminAuthenticated()) {
$router = new Router($this);
$controller = $router->getController();
} else {
require dirname(__FILE__) . '/modules/connexion/ConnexionController.class.php';
$controller = new ConnexionController($this, 'connexion', 'index');
}
if (!is_null($controller)) {
$controller->execute();
$this->httpResponse->setPage($controller->page());
}
}
示例10: invokeController
/**
* Invoke controller based on URL structure
*/
function invokeController()
{
$url = "";
if (isset($_GET['url'])) {
$url = $_GET['url'];
}
/** @var ControllerInterface $controller */
$controller = Router::getController($url);
if ((int) method_exists($controller, $controller->getAction() . 'Action')) {
call_user_func_array(array($controller, $controller->getAction() . 'Action'), array());
} else {
/* Error Generation Code Here */
}
}
示例11: displaySingle
public function displaySingle($file = null, $data = null, $print = true)
{
if ($file == null) {
throw new Exception('模板文件错误');
}
$file = Router::getController() . "/" . $file;
if (is_array($data)) {
foreach ($data as $k => $v) {
$this->smarty->assign($k, $v);
}
}
if ($print) {
ob_start();
$this->smarty->display($file . ".html");
ob_end_flush();
return;
} else {
return $this->smarty->fetch($file . ".html");
}
}
示例12: __construct
public function __construct()
{
// parent::__construct();
config::getInstance();
config::getConfig();
$router = new Router();
$router->explodeUri();
/*
apenas para checagem dos caminhos
//echo '<p>ROUT FILE: '.$routFile.'</p>';
echo '<pre >';
echo '<p>ROTA COMPLETA: '.$this->getRoute().'</p>';
echo '<p>NOME Controller: '.$this->getController().'</p>';
echo '<p>NOME METODO: '.$this->getAction().'</p>';
echo '</pre>';
*/
define('ROUTE', $router->getRoute());
define('CONTROLLER', $router->getController());
define('ACTION', $router->getAction());
$filename = BASEPATH . DIRECTORY_SEPARATOR . APPPATH . DIRECTORY_SEPARATOR . CONTROLLERS . DIRECTORY_SEPARATOR . ROUTE . CONTROLLER . '.controller.php';
if (file_exists($filename)) {
require_once $filename;
$_controllerName = CONTROLLER;
$_controller = new $_controllerName();
$action = ACTION;
if (method_exists($_controller, $action)) {
$_controller->{$action}();
} else {
require_once BASEPATH . DIRECTORY_SEPARATOR . APPPATH . DIRECTORY_SEPARATOR . CONTROLLERS . DIRECTORY_SEPARATOR . 'error404.controller.php';
$errorController = new error404();
$errorController->index();
}
} else {
require_once BASEPATH . DIRECTORY_SEPARATOR . APPPATH . DIRECTORY_SEPARATOR . CONTROLLERS . DIRECTORY_SEPARATOR . 'error404.controller.php';
$errorController = new error404();
$errorController->index();
}
}
示例13: __construct
public function __construct()
{
$this->controller = Router::getController();
}
示例14: __autoload
<?php
//test
session_start();
$_SESSION['auth'] = 'user';
require_once 'router.php';
require_once 'baseController.php';
function __autoload($class)
{
$class = './controllers/' . $class . '.php';
require_once $class;
}
$router = new Router();
$controller = $router->getController();
$action = $router->getAction();
$obj = new $controller();
$obj->{$action}();
示例15: defined
<?php
defined(SYS_PATH) or define("SYS_PATH", dirname(__FILE__) . "/");
require_once SYS_PATH . "classes/loader.php";
ini_set("display_errors", 1);
Loader::addAutoLoad();
Loader::addMap();
Registry::init();
Router::addMap();
Router::init();
var_dump(Router::getParams());
if (Router::getParams() == NULL) {
Subdomain::init();
}
$controller = Router::getController();
$action = Router::getAction();
if ($controller == 'site' or $controller == 'admin' or $controller == 'stylecheet') {
$controller::init($action);
} else {
header("Location: http://myclankonto.net/");
}