本文整理汇总了PHP中Yaf_Dispatcher::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Yaf_Dispatcher::getInstance方法的具体用法?PHP Yaf_Dispatcher::getInstance怎么用?PHP Yaf_Dispatcher::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yaf_Dispatcher
的用法示例。
在下文中一共展示了Yaf_Dispatcher::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$this->groupTable = Sys_Database::getTable('worker');
$this->alarmModel = $this->loadModel();
if ($this->getRequest()->getPost('o') == 'delete') {
$gid = $this->getRequest()->getPost('gid');
$this->delete($gid);
}
if ($this->getRequest()->getQuery('o') == 'edit') {
Yaf_Dispatcher::getInstance()->disableView();
$this->initView();
$configData = array();
$id = $this->getRequest()->getQuery('id');
if ($id) {
$configDataTmp = $this->alarmModel->selectData($id, 1, 1, $this->groupTable);
$configData = $configDataTmp[0];
}
$this->display('addworker', array('D' => $configData));
}
if ($this->getRequest()->getQuery('o') == 'add') {
$this->add();
}
$page = $this->getRequest()->getQuery('p');
$alarmList['page'] = $page ? $page : 1;
$id = $this->getRequest()->getQuery('pluginid');
$pid = $id ? $id : NULL;
$limit = 20;
$alarmList['list'] = $this->alarmModel->selectData($pid, ($alarmList['page'] - 1) * $limit, $limit, $this->groupTable);
$alarmNum = $this->alarmModel->selectData($pid, -1, -1, $this->groupTable);
$alarmList['num'] = $alarmNum['num'];
$alarmList['pageCount'] = (int) ($alarmList['num'] / $limit) + 1;
$alarmList['pageView'] = $this->page($alarmList['page'], $alarmList['pageCount']);
$this->getView()->assign('alarmList', $alarmList);
}
示例2: routerShutdown
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
{
$config = \Yaf_Registry::get('configarr');
$dispatcher = Yaf_Dispatcher::getInstance();
$twig = '';
// view 放在module 目录里
if ($request->module == $config['application']['dispatcher']['defaultModule']) {
$twig = new \Core_Twig(APP_PATH . 'views', $config['twig']);
} else {
$twig = new \Core_Twig(APP_PATH . 'modules/' . $request->module . '/views', $config['twig']);
}
// url generate
$twig->twig->addFunction("url", new Twig_Function_Function("Tools_help::url"));
// 语言对应
$twig->twig->addFunction("lang", new Twig_Function_Function("Tools_help::lang"));
// 图片路径
$twig->twig->addFunction("fbu", new Twig_Function_Function("Tools_help::fbu"));
// 数字验证
$twig->twig->addFunction("is_numeric", new Twig_Function_Function("is_numeric"));
// 处理错误提醒
$session_key = array('ErrorMessageStop', 'ErrorMessage', 'Message');
foreach ($session_key as $value) {
$twig->assign($value, Tools_help::getSession($value));
Tools_help::setSession($value, '');
}
$dispatcher->setView($twig);
}
示例3: routerStartup
/**
* 路由分发开始
*
* @see Yaf_Plugin_Abstract::routerShutdown()
*/
public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
{
//IIS不支持默认路由,采用URL Query String方式路由
$router = Yaf_Dispatcher::getInstance()->getRouter();
$route = new Yaf_Route_Simple('m', 'c', 'a');
$router->addRoute('Windows-IIS-Supervar', $route);
}
示例4: _initRoute
function _initRoute()
{
# 路由
$router = Yaf_Dispatcher::getInstance()->getRouter();
# 静态页面
$router->addRoute('html', new Yaf_Route_Regex('/([a-z]+)\\.html$/', array('controller' => 'Index', 'action' => 'html'), array(1 => 'page')));
}
示例5: init
/**
* 初始化 REST 路由
* 修改操作 和 绑定参数
* @method init
* @author NewFuture
*/
protected function init()
{
Yaf_Dispatcher::getInstance()->disableView();
//关闭视图模板引擎
$action = $this->_request->getActionName();
//数字id映射带info控制器
if (is_numeric($action)) {
$this->_request->setParam('id', intval($action));
$path = substr(strstr($_SERVER['PATH_INFO'], $action), strlen($action) + 1);
$action = $path ? strstr($path . '/', '/', true) : 'info';
$this->_request->setActionName($action);
}
//对应REST_Action
$method = $this->_request->getMethod();
$rest_action = $method . '_' . $action;
/*检查该action操作是否存在,存在则修改为REST接口*/
if (method_exists($this, $rest_action . 'Action')) {
/*存在对应的操作*/
$this->_request->setActionName($rest_action);
} elseif (!method_exists($this, $action . 'Action')) {
/*action和REST_action 都不存在*/
$this->response = array('error' => '未定义操作', 'method' => $method, 'action' => $action, 'controller' => $this->_request->getControllerName());
exit;
}
//put请求写入GOLBAL中
$method == 'PUT' and parse_str(file_get_contents('php://input'), $GLOBALS['_PUT']);
}
示例6: ScaffoldRoute
/**
*Scaffold action识配
*/
protected function ScaffoldRoute()
{
if (!$this->Scaffold) {
return;
}
$this->set('controller', $this->getRequest()->getControllerName());
$this->allParams();
Yaf_Dispatcher::getInstance()->disableView();
$action = $this->getRequest()->getActionName();
if ($action == 'c') {
$this->scaffoldC = TRUE;
$action = $this->getRequest()->getParam('action');
}
switch ($action) {
case 'scaffoldajax':
$this->ScaffoldAjax();
break;
case 'scaffold':
$this->ScaffoldIndex();
break;
case 'getrow':
$this->ScaffoldGetrow();
break;
case 'modify':
$this->ScaffoldModify();
break;
case 'remove':
$this->ScaffoldRemove();
break;
default:
$this->ScaffoldIndex();
}
}
示例7: __construct
public function __construct()
{
$app = self::app();
if (!is_null($app)) {
throw new Yaf_Exception('Only one application can be initialized');
}
Yaf_G::init();
//这里主要是配置文件的加载
// request initialization
if (isset($_SERVER['REQUEST_METHOD'])) {
//判断http请求还是cli请求
$request = new Yaf_Request_Http();
//获取请求的url路径和基础路径,以及请求方式
} else {
$request = new Yaf_Request_Cli();
}
if ($request == null) {
throw new Yaf_Exception('Initialization of request failed');
}
// dispatcher
$this->_dispatcher = Yaf_Dispatcher::getInstance();
//将调度对象赋值给app对象的属性,并在调度对象的属性中添加路由对象,单例
if ($this->_dispatcher == null || !$this->_dispatcher instanceof Yaf_Dispatcher) {
throw new Yaf_Exception('Instantiation of dispatcher failed');
}
$this->_dispatcher->setRequest($request);
//把请求对象赋值给调度对象的属性中
self::$_app = $this;
}
示例8: init
public function init()
{
if (Yaf_Session::getInstance()->has('username')) {
$this->getView()->assign('username', Yaf_Session::getInstance()->offsetGet('username'));
} else {
return $this->redirect('/Login');
}
$dsn = 'mysql:host=127.0.0.1;dbname=yafdemo;charset=utf8';
$username = 'root';
$password = 'root';
$dbo = new PDO($dsn, $username, $password);
$dbo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$dbo->exec('SET NAMES UTF8');
$this->dbo = $dbo;
$request = $this->getRequest();
$module = strtolower($request->getModuleName());
$controller = strtolower($request->getControllerName());
$action = strtolower($request->getActionName());
if (!$this->_checkPerm($module, $controller, $action) && $action != 'logout') {
$this->getView()->setScriptPath(APPLICATION_PATH . "/application/views");
$this->getView()->display('common/403.phtml');
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
exit;
}
}
示例9: _initRoute
public function _initRoute()
{
$router = Yaf_Dispatcher::getInstance()->getRouter();
// Article detail router [伪静态]
$route = new Yaf_Route_Rewrite('/article/detail/:articleID', array('controller' => 'article', 'action' => 'detail'));
$router->addRoute('regex', $route);
}
示例10: testCase036
/**
* @runInSeparateProcess
*/
public function testCase036()
{
$testData = array(0 => array('url' => '/', 'expected' => array('m' => null, 'c' => null, 'a' => null, 'args' => array())), 1 => array('url' => '/foo', 'expected' => array('m' => null, 'c' => 'foo', 'a' => null, 'args' => array())), 2 => array('url' => '/foo/', 'expected' => array('m' => null, 'c' => 'foo', 'a' => null, 'args' => array())), 3 => array('url' => '/foo///bar', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array())), 4 => array('url' => 'foo/bar', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array())), 5 => array('url' => '/foo/bar/', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array())), 6 => array('url' => '/foo/bar/dummy', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => null))), 7 => array('url' => '/foo///bar/dummy', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => null))), 8 => array('url' => 'foo/bar/dummy', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => null))), 9 => array('url' => '/my', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 10 => array('url' => '/my/', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 11 => array('url' => '/my/foo', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())), 12 => array('url' => '/my/foo/', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())), 13 => array('url' => '/my/foo/bar', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array())), 14 => array('url' => '/my/foo/bar/', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array())), 15 => array('url' => '/my/foo/bar/dummy/1', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => '1'))), 16 => array('url' => 'my/foo/bar/dummy/1/a/2/////', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => '1', 'a' => '2'))), 17 => array('url' => '/my/index/index', 'expected' => array('m' => 'my', 'c' => 'index', 'a' => 'index', 'args' => array())), 18 => array('url' => '/my/index', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'index', 'args' => array())), 19 => array('url' => '/foo/index', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'index', 'args' => array())), 20 => array('url' => 'index/foo', 'expected' => array('m' => null, 'c' => 'index', 'a' => 'foo', 'args' => array())));
$config = array("application" => array("directory" => '/tmp/', "modules" => 'Index,My'));
$app = new Yaf_Application($config);
$route = Yaf_Dispatcher::getInstance()->getRouter();
foreach ($testData as $index => $test) {
$req = new Yaf_Request_Http($test['url']);
$route->route($req);
$this->assertEquals($test['expected']['m'], $req->getModuleName(), 'Failed module test for url:' . $test['url']);
$this->assertEquals($test['expected']['c'], $req->getControllerName(), 'Failed controller test for url:' . $test['url']);
$this->assertEquals($test['expected']['a'], $req->getActionName(), 'Failed action test for url:' . $test['url']);
$this->assertEquals($test['expected']['args'], $req->getParams(), 'Failed param test for url:' . $test['url']);
}
if (!defined('YAF_MODE')) {
Yaf_G::iniSet('yaf.action_prefer', true);
} else {
ini_set('yaf.action_prefer', true);
}
$testDataActionPrefer = array(0 => array('url' => '/', 'expected' => array('m' => null, 'c' => null, 'a' => null, 'args' => array())), 1 => array('url' => '/foo', 'expected' => array('m' => null, 'c' => null, 'a' => 'foo', 'args' => array())), 2 => array('url' => '/foo/', 'expected' => array('m' => null, 'c' => null, 'a' => 'foo', 'args' => array())), 3 => array('url' => '/my', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 4 => array('url' => '/my/', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 5 => array('url' => '/my/foo', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())), 6 => array('url' => '/my//foo', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())));
foreach ($testDataActionPrefer as $index => $test) {
$req = new Yaf_Request_Http($test['url']);
$route->route($req);
$this->assertEquals($test['expected']['m'], $req->getModuleName(), 'Failed module test for url:' . $test['url']);
$this->assertEquals($test['expected']['c'], $req->getControllerName(), 'Failed controller test for url:' . $test['url']);
$this->assertEquals($test['expected']['a'], $req->getActionName(), 'Failed action test for url:' . $test['url']);
$this->assertEquals($test['expected']['args'], $req->getParams(), 'Failed param test for url:' . $test['url']);
}
}
示例11: errorAction
function errorAction($exception)
{
// fallback views path to global when error occured in modules.
$config = Yaf_Application::app()->getConfig();
$this->getView()->setScriptPath($config->application->directory . "/views");
$this->getView()->e = $exception;
$this->getView()->e_class = get_class($exception);
$this->getView()->e_string_trace = $exception->getTraceAsString();
$params = $this->getRequest()->getParams();
unset($params['exception']);
$this->getView()->params = array_merge(array(), $params, $this->getRequest()->getPost(), $this->getRequest()->getQuery());
switch ($exception->getCode()) {
case YAF_ERR_AUTOLOAD_FAILED:
case YAF_ERR_NOTFOUND_MODULE:
case YAF_ERR_NOTFOUND_CONTROLLER:
case YAF_ERR_NOTFOUND_ACTION:
header('HTTP/1.1 404 Not Found');
break;
case 401:
$this->forward('Index', 'application', 'accessDenied');
header('HTTP/1.1 401 Unauthorized');
Yaf_Dispatcher::getInstance()->disableView();
echo $this->render('accessdenied');
break;
default:
//header("HTTP/1.1 500 Internal Server Error");
core::dump($exception);
break;
}
}
示例12: init
/**
* Controller的init方法会被自动首先调用
*/
public function init()
{
//调试mysql
if (isset($_GET['debug6429360'])) {
$this->debug = true;
DB_Mysqli::$DEBUG = 1;
}
$this->platform = isset($_REQUEST['platform']) ? $_REQUEST['platform'] : $this->platform;
Yaf_Registry::set("platform", $this->platform);
$this->isMobile = $this->platform == 'ios' || $this->platform == 'android';
$this->wap = !$this->isMobile && Common_Mobile::isMobile();
$this->uid = $this->get('uid', $this->post('uid', false));
$this->controllerName = $this->getRequest()->getControllerName();
$this->actionName = $this->getRequest()->getActionName();
$userModel = new UserModel();
/* if (!isset(Common_Config::$NotNeedLogin[$this->controllerName][$this->actionName])
&& $this->isMobile
&& $this->needLogin
&& !$this->debug)
{
$token = $this->get("token", $this->post("token", false));
if (!$token) {
$this->redirect(NULL, Common_Error::ERROR_TOKEN_NOT_EXISTS);
}
$api = $this->getRequestApi();
$check = Common_Token::check($token, $this->uid, strtolower($api));
if (!$check) {
$this->redirect(NULL, Common_Error::ERROR_TOKEN);
}
}*/
$this->uid = $this->uid ? $this->uid : $userModel->getUid();
/**
* 如果是Ajax请求, 则关闭HTML输出
*/
if ($this->getRequest()->isXmlHttpRequest() || 'POST' == $this->getRequest()->getMethod()) {
$this->ajax = true;
Yaf_Dispatcher::getInstance()->disableView();
} else {
//$path = $this->getView()->getScriptPath();
//$path[0] = $path[0] . "/" . strtolower($this->getRequest()->getControllerName());
//$this->getView()->setScriptPath($path[0]);
}
//print_r($this->uid?$this->uid:"null");
//验证登录
/*if (
!isset(Common_Config::$NotNeedLogin[$this->controllerName][$this->actionName])
&& $this->needLogin
&& !$this->uid) {
$this->redirect("/user/login?from=" . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""), Common_Error::ERROR_USER_NOT_LOGIN);
$this->redirect("/user/verify", Common_Error::ERROR_USER_NOT_LOGIN);
}*/
//用户信息
/* if($this->uid) {
$user = $userModel->getUser($this->uid);
$this->assign("uInfo", $user);
Yaf_Registry::set("uid", $this->uid);
}*/
}
示例13: dispatchLoopStartup
public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
{
$view = new TZ_View();
$view->setCacheEnable(true);
$view->setScriptPath(APP_PATH . '/application/modules/' . $request->getModuleName() . '/views');
Yaf_Dispatcher::getInstance()->setView($view);
}
示例14: _initRoute
/**
* 路由规则定义,如果没有需要,可以去除该代码
*
* @param Yaf_Dispatcher $dispatcher
*/
public function _initRoute(Yaf_Dispatcher $dispatcher)
{
$config = new Yaf_Config_Ini(APPLICATION_PATH . '/conf/route.ini', 'common');
if ($config->routes) {
$router = Yaf_Dispatcher::getInstance()->getRouter();
$router->addConfig($config->routes);
}
}
示例15: _initRoute
/**
*初始化路由
*/
public function _initRoute(Yaf_Dispatcher $dispatcher)
{
$router = Yaf_Dispatcher::getInstance()->getRouter();
/**
* 添加配置中的路由
*/
$router->addConfig(Yaf_Registry::get("config")->routes);
}