本文整理汇总了PHP中Dispatcher::getController方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::getController方法的具体用法?PHP Dispatcher::getController怎么用?PHP Dispatcher::getController使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::getController方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: get
public static function get($params, $print = true)
{
$get = Dispatcher::getController()->getParams();
foreach ($params as $key => $value) {
if (is_null($value)) {
unset($get[$key]);
} else {
$get[$key] = $value;
}
}
$query = '';
if (count($get) > 0) {
$query = '?' . http_build_query($get);
}
$url = 'index.php' . $query;
if ($print) {
echo $url;
} else {
return $url;
}
}
示例3: header
* Please see license.txt for the full license text.
*/
/**
* @package Layouts
*/
/* Security measure */
if (!defined('IN_CMS')) {
exit;
}
// Redirect to front page if user doesn't have appropriate roles.
if (!AuthUser::hasPermission('admin_view')) {
header('Location: ' . URL_PUBLIC . ' ');
exit;
}
// Setup some stuff...
$ctrl = Dispatcher::getController(Setting::get('default_tab'));
// Allow for nice title.
// @todo improve/clean this up.
$title = $ctrl == 'plugin' ? Plugin::$controllers[Dispatcher::getAction()]->label : ucfirst($ctrl) . 's';
if (isset($this->vars['content_for_layout']->vars['action'])) {
$tmp = $this->vars['content_for_layout']->vars['action'];
$title .= ' - ' . ucfirst($tmp);
if ($tmp == 'edit' && isset($this->vars['content_for_layout']->vars['page'])) {
$tmp = $this->vars['content_for_layout']->vars['page'];
$title .= ' - ' . $tmp->title;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
示例4: datepicker
public function datepicker($label, $name, $required = false)
{
$input = $this->createElement('input');
$this->setAttribute($input, 'type', 'text');
$this->setAttribute($input, 'id', $name . '_alternate');
$this->setAttribute($input, 'class', 'form-control');
$hidden = $this->input('hidden', $name);
$this->setAttribute($hidden, 'id', $name);
$label = $this->getLabel($label, $name, $required);
$container = $this->getContainer();
$container->appendChild($label);
$container->appendChild($input);
$container->appendChild($hidden);
$this->elements[$name] = $container;
if ($this->append_children) {
$this->form->appendChild($container);
}
$locale = Dispatcher::getController()->getLocale();
Dispatcher::getController()->getLayout()->addReadyJs('
$("#' . $name . '_alternate").datepicker({
altField: "#' . $name . '",
altFormat: "yy-mm-dd",
dateFormat: "' . $locale['jquery_ui_datepicker_user_date_format'] . '"
});
');
if (isset($this->data[$name])) {
$value = $this->data[$name];
//data nel formato del database yyyy-mm-dd
$datetime = DateTime::createFromFormat('Y-m-d', $value);
$value = $datetime->format($locale['php_user_date_format']);
Dispatcher::getController()->getLayout()->addReadyJs('
$("#' . $name . '_alternate").datepicker("setDate", "' . $value . '");
');
}
return $this;
}
示例5: test_getController_02
public function test_getController_02()
{
$this->setExpectedException('DCException', 'FooController is not found');
Dispatcher::getController('foo');
}
示例6: header
<?php
if (!AuthUser::hasPermission('administrator,developer,editor')) {
header('Location: ' . URL_PUBLIC . ' ');
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><?php
use_helper('Kses');
echo kses(Setting::get('admin_title'), array()) . ' - ' . ucfirst($ctrl = Dispatcher::getController(Setting::get('default_tab')));
?>
</title>
<base href="<?php
echo trim(BASE_URL, '?/') . '/';
?>
" />
<link rel="favourites icon" href="<?php
echo URL_PUBLIC;
?>
favicon.ico" />
<link href="stylesheets/admin.css" media="screen" rel="Stylesheet" type="text/css" />
<link href="stylesheets/toolbar.css" media="screen" rel="Stylesheet" type="text/css" />
<link href="themes/<?php
示例7: ucfirst
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><?php
echo Setting::get('admin_title') . ' - ' . ucfirst($ctrl = Dispatcher::getController());
?>
</title>
<base href="<?php
echo trim(BASE_URL, '?/') . '/';
?>
" />
<link href="stylesheets/admin.css" media="screen" rel="Stylesheet" type="text/css" />
<link href="stylesheets/toolbar.css" media="screen" rel="Stylesheet" type="text/css" />
<link href="themes/<?php
echo Setting::get('theme');
?>
/styles.css" id="css_theme" media="screen" rel="Stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="javascripts/prototype.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/effects.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/dragdrop.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/cp-datepicker.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/frog.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/control.textarea.js"></script>
<?php
foreach (Plugin::$plugins as $plugin_id => $plugin) {