本文整理汇总了PHP中Router::getAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getAction方法的具体用法?PHP Router::getAction怎么用?PHP Router::getAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::getAction方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public static function execute()
{
static::check('action', Router::getTemplateAction());
static::check('action', Router::getAction());
static::check('view', Router::getView());
static::check('view', Router::getTemplateView());
}
示例2: 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;
}
示例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: 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;
}
示例5: __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
}
}
示例6: run
public static function run()
{
$router = new Router();
$dispatcher = new Dispatcher($router, array("requireViewFile" => !in_array($router->getAction(), array_keys(static::$actionsWithDataOnly))));
static::$dispatcher =& $dispatcher;
$action = $dispatcher->getAction();
$controller = $dispatcher->getController();
$lang = $dispatcher->getLang();
$module = $dispatcher->getModule();
$permission = $dispatcher->getPermission();
$view = $dispatcher->getView();
$info = array("action" => $action, "controller" => $controller, "data" => $dispatcher->getData(), "extra" => $dispatcher->getExtra(), "lang" => $lang, "module" => $module, "view" => $view);
if ($permission::getPermission($action, Session::getPerm(), $info) === false) {
$dispatcher->setError(403);
$info["action"] = $action = $dispatcher->getAction();
$info["controller"] = $controller = $dispatcher->getController();
$info["module"] = $module = $dispatcher->getModule();
$info["view"] = $view = $dispatcher->getView();
}
//TASK: przeniesc do __constructStatic, znalezc inne wywolania __init i to samo!
$view::__init($action);
$view::obStart();
if (array_key_exists($action, static::$actionsWithDataOnly)) {
header("Content-Type: " . static::$actionsWithDataOnly[$action]);
//TODO: czy metody withDataOnly powinny otrzymywac argument $viewParams["info"] ?
if (is_callable(array($controller, $action))) {
echo $controller::$action();
} elseif (is_callable(array($controller, "{$action}_"))) {
$action2 = "{$action}_";
echo $controller::$action2();
}
} else {
if (Config::getOne("requireWww")) {
Utils\Header::redirectIfNotWww();
}
$viewParams = array("info" => $info);
// Troche magii:
// Jesli mamy modul, w ktorym akcja nazywa sie tak samo jak modul - to PHP uzna akcje za konstruktor, lecz ten nie moze byc statyczny wiec bedzie blad PHP.
// Wtedy definiujemy akcje jako z sufixem "_" (np. "AKCJA_"), a tu umozliwiamy jej wywolanie.
// Przyklad: \App\Controller\Index::index
if (is_callable(array($controller, $action))) {
$viewParams["data"] = $controller::$action($viewParams["info"]);
} elseif (is_callable(array($controller, "{$action}_"))) {
$action2 = "{$action}_";
$viewParams["data"] = $controller::$action2($viewParams["info"]);
}
$bodyContent = static::loadViewFile($view::getViewFile($lang, $module, $action), $viewParams);
$headerContent = static::loadViewFile($view::getViewFile($lang, "common", "header"), $viewParams);
$view::printSite(["bodyHeader" => $headerContent, "body" => $bodyContent, "info" => $info]);
}
$view::obFinish();
}
示例7: 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);
}
}
示例8: __construct
public function __construct(Router $_router, $_ = array())
{
$this->lang = $_router->getLang();
if (!in_array($this->lang, \Ker\Config::getOne("allowedLanguages"))) {
$this->lang = \Ker\Config::getOne("defaultLanguage");
$this->setError(404);
return;
}
$this->module = $_router->getModule();
$this->action = $_router->getAction();
$this->data = $_router->getData();
$this->extra = $_router->getExtra();
$view = $this->getView();
if (!$this->module) {
$this->module = "Index";
$this->action = "index";
} elseif (isset($_["requireViewFile"]) and $_["requireViewFile"] and !file_exists($view::getViewFile($this->lang, $this->module, $this->action))) {
$this->setError(404);
}
}
示例9: __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();
}
}
示例10: __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}();
示例11: default_assign
public function default_assign()
{
$global_assign = array('user_info' => isset($_SESSION['user_info']) ? $_SESSION['user_info'] : "", 'static_url' => Config::get('static_url'), 'base_url' => Config::get('app_url'), 'cur_url' => Router::getController() . "/" . Router::getAction() . "/", 'menus' => $this->_getMenus());
$this->view->assign($global_assign);
}
示例12: ob_end_flush
require Router::getTemplateAction();
}
if (ob_get_contents()) {
ob_end_flush();
trigger_error('MindaPHP template action"' . Router::getTemplateAction() . '" should not send output. Error raised ', E_USER_WARNING);
} else {
ob_end_clean();
}
ob_start();
if (Router::getAction()) {
extract(Router::getParameters());
require Router::getAction();
}
if (ob_get_contents()) {
ob_end_flush();
trigger_error('MindaPHP action "' . Router::getAction() . '" should not send output. Error raised ', E_USER_WARNING);
} else {
ob_end_clean();
}
// End the session
Session::end();
// Close the database connection
DB::close();
if (Router::getTemplateView()) {
Buffer::start('html');
require Router::getView();
// Show developer toolbar
if (Debugger::$enabled) {
Debugger::toolbar();
}
Buffer::end('html');
示例13: 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/");
}
示例14: dispatch
/**
* Run the application.
*
* @api
*/
public function dispatch()
{
# get current context from URL
try {
Router::resolve(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/');
Router::updateHtaccess();
#Router::updateRules();
} catch (\Exception $e) {
Session::addErrorMsg($e->getMessage());
}
// from here we'll capture every output
ob_start();
// we need the session this early, (feel free to remove the following line and get stuck with session problems)
Session::getInstance();
$module = Router::getModule();
$action = Router::getAction();
$view = $this->handleRequest($module, $action);
// threat all unwanted output as error output
$errors = ob_get_clean();
if (trim($errors) !== '') {
Session::addErrorMsg($errors);
}
// finally deliver page
$view->display();
}