public function _init(Yaf_Dispatcher $dispatcher) { // auto start session Yaf_Session::getInstance()->start(); // auto load config data $this->config = Yaf_Application::app()->getConfig(); Yaf_Registry::set('Config', $this->config); //auto load redis $redis = new Redis(); $redis->connect($this->config->redis->host, $this->config->redis->port, $this->config->redis->timeout, $this->config->redis->reserved, $this->config->redis->interval); Yaf_Registry::set('Redis', $redis); //auto load mysql Yaf_Registry::set('DbRead', new Db('mysql:host=' . $this->config->mysql->read->host . ';dbname=' . $this->config->mysql->read->dbname . ';charset=' . $this->config->mysql->read->charset . ';port=' . $this->config->mysql->read->port . '', $this->config->mysql->read->username, $this->config->mysql->read->password)); Yaf_Registry::set('DbWrite', new Db('mysql:host=' . $this->config->mysql->write->host . ';dbname=' . $this->config->mysql->write->dbname . ';charset=' . $this->config->mysql->write->charset . ';port=' . $this->config->mysql->write->port . '', $this->config->mysql->write->username, $this->config->mysql->write->password)); // auto load model Yaf_Registry::set('I18n', new I18nModel($redis, $this->config->application->name, 'cn')); Yaf_Registry::set('Cache', new CacheModel($redis, $this->config->application->name)); // auto load plugin $dispatcher->registerPlugin(new GlobalPlugin()); // auto save request $request = $dispatcher->getRequest(); // auto set ajax is no render if ($request->isXmlHttpRequest()) { $dispatcher->autoRender(false); } // auto set http protocol to action except http get protocol if (!$request->isGet()) { $dispatcher->setDefaultAction($request->getMethod()); } }
public function _initRoute(Yaf_Dispatcher $dispatcher) { // 编辑员工 $dispatcher->getRouter()->addRoute('staffUpdateRewrite', new Yaf_Route_Rewrite('/admin/staff/update/:userId', array('module' => 'admin', 'controller' => 'staff', 'action' => 'update'))); // 删除员工 $dispatcher->getRouter()->addRoute('staffDeleteRewrite', new Yaf_Route_Rewrite('/admin/staff/delete/:userId', array('module' => 'admin', 'controller' => 'staff', 'action' => 'delete'))); }
public function _initSmarty(Yaf_Dispatcher $dispatcher) { /* init smarty view engine */ Yaf_Loader::import("Smarty/Adapter.php"); $smarty = new Smarty_Adapter(null, Yaf_Application::app()->getConfig()->smarty); $dispatcher->setView($smarty); }
/** * * @param \Yaf_Dispatcher $dispatcher * @param string $jqueryVer 使用的jquery文件,默认值:jquery-1.11.2.min.js * @return view */ public static function initYafBySooh($dispatcher, $jqueryVer = 'jquery-1.11.2.min.js') { $router = $dispatcher->getRouter(); $router->addRoute("byVar", new \Yaf_Route_Supervar(SOOH_ROUTE_VAR)); \Yaf_Loader::getInstance()->registerLocalNameSpace($GLOBALS['CONF']['localLibs']); $req = $dispatcher->getRequest(); $tmp = $req->get('__ONLY__'); if ($tmp == 'body') { \SoohYaf\Viewext::$bodyonly = true; } $tmp = trim($req->get('__VIEW__')); //html(default),wap, json define('VIW_INC_PATH', APP_PATH . '/application/views/_inc/'); \SoohYaf\Viewext::$jqueryVer = $jqueryVer; if (!empty($tmp)) { $tmp = strtolower($tmp); \Sooh\Base\Ini::getInstance()->viewRenderType($tmp); if ($tmp == 'jsonp') { \Sooh\Base\Ini::getInstance()->initGobal(array('nameJsonP' => $req->get('jsonp', 'jsonp'))); } } // $tmp = $dispatcher->getRequest()->get('__GZIP__'); // if(!empty($tmp)){ // $tmp = strtolower ($tmp); // if($tmp=='gzip')define("ZIP_OUTPUT",$tmp); // } $view = new \SoohYaf\Viewext(null); $dispatcher->setView($view); $dispatcher->registerPlugin(new SoohPlugin()); return $view; }
/** * [路由设置] */ public function _initRoutes(Yaf_Dispatcher $dispatcher) { $router = $dispatcher->getRouter(); //$router->addConfig(Yaf_Registry::get('config')->routes); Yaf_Loader::import(APP_CONFIG . '/route.php'); $router->addConfig($routeConfigs); }
function _initPlugin(Yaf_Dispatcher $dispatcher) { Yaf_Loader::import('vendor/autoload.php'); $dispatcher->registerPlugin(new Plugin_Init()); $dispatcher->registerPlugin(new Plugin_Smarty()); $dispatcher->registerPlugin(new LoginPlugin()); }
protected function _initView(Yaf_Dispatcher $dispatcher) { $view = new YafView(APPLICATION_VIEW_SCRIPTS_PATH); $view->enableLayout('layout/normal.phtml'); $dispatcher->setView($view); // $dispatcher->setView(new YafView(APPLICATION_VIEW_SCRIPTS_PATH)); }
/** * 初始化plugin(插件) */ public function _initPlugin(Yaf_Dispatcher $dispatcher) { //注册xhprof插件 if (isset($this->_config->application->xhprof) && $this->_config->application->xhprof) { $XHProf = new XHProfPlugin(); $dispatcher->registerPlugin($XHProf); } }
public function _initPlugin(Yaf_Dispatcher $dispatcher) { $router = new RouterPlugin(); $dispatcher->registerPlugin($router); $admin = new AdminPlugin(); $dispatcher->registerPlugin($admin); Yaf_Registry::set('adminPlugin', $admin); }
public function _initDefaultName(Yaf_Dispatcher $dispatcher) { //echo "_initDefaultName call last<br/>\n"; /** * actully this is unecessary, since all the parameters here is the default value of Yaf */ $dispatcher->setDefaultModule("Index")->setDefaultController("Index")->setDefaultAction("index"); }
public function _initView(Yaf_Dispatcher $dispatcher) { //在这里注册自己的view控制器,例如smarty,firekylin $smarty = new Smarty_Adapter(null, Yaf_Registry::get("config")->get("smarty")); Yaf_Registry::set("smarty", $smarty); $dispatcher->setView($smarty); //Yaf_Dispatcher::getInstance()->disableView(); //var_dump('sssss'); }
/** * Start Yaf_Application */ public function run() { if ($this->_running == true) { throw new Yaf_Exception('An application instance already run'); } else { $this->_running = true; return $this->_dispatcher->dispatch(); } }
public function _initPlugin(Yaf_Dispatcher $dispatcher) { //echo 'aaa'; //include (APP_PATH.'/plugins/UserPlugin.php'); $user = new UserPlugin(); // echo 'cccc'; $dispatcher->registerPlugin($user); //echo 'fff'; }
public function _initRoute(Yaf_Dispatcher $dispatcher) { //在这里注册自己的路由协议,默认使用简单路由 $fileName = APPLICATION_PATH . "/conf/routes.ini"; if (file_exists($fileName)) { $config = new Yaf_Config_Ini($fileName); $dispatcher->getRouter()->addConfig($config->routes); } }
public function _initRoute(Yaf_Dispatcher $dispatcher) { //在这里注册自己的路由协议,默认使用简单路由 $router = $dispatcher->getRouter(); //创建一个路由协议实例 $router->addRoute('index', new Yaf_Route_Regex('#^/$#', array('controller' => 'index', 'action' => 'index'))); $router->addRoute('country', new Yaf_Route_Rewrite('route/:country', array('controller' => 'router', 'action' => 'country'))); $router->addRoute('province', new Yaf_Route_Rewrite('route/:country/:province', array('controller' => 'router', 'action' => 'province'))); $router->addRoute('city', new Yaf_Route_Rewrite('route/:country/:province/:city', array('controller' => 'router', 'action' => 'city'))); }
/** * Singleton instance * * @return Yaf_Dispatcher */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); self::$_instance->setDefaultAction(Yaf_G::get('default_action')); self::$_instance->setDefaultController(Yaf_G::get('default_controller')); self::$_instance->setDefaultModule(Yaf_G::get('default_module')); self::$_instance->_router = new Yaf_Router(); } return self::$_instance; }
public function _initLayout(Yaf_Dispatcher $dispatcher) { /*layout allows boilerplate HTML to live in /views/layout rather than every script*/ $layout = new LayoutPlugin('layout.phtml'); /* Store a reference in the registry so values can be set later. * This is a hack to make up for the lack of a getPlugin * method in the dispatcher. */ Yaf_Registry::set('layout', $layout); /*add the plugin to the dispatcher*/ $dispatcher->registerPlugin($layout); }
/** * 采用布局 * @param Yaf_Dispatcher $dispatcher */ function _initLayout(Yaf_Dispatcher $dispatcher) { define('REDIRECT_URL', empty($_SERVER['REQUEST_URI']) ? '/' : strtolower($_SERVER['REQUEST_URI'])); # 用户后台 if (false !== strpos(REDIRECT_URL, '/user_emailverify')) { return; } if (false !== strpos(REDIRECT_URL, '/user_') || false !== strpos(REDIRECT_URL, '/huodong_') || false !== strpos(REDIRECT_URL, '/loan_')) { $layout = new LayoutPlugin('user/tpl.layout.phtml'); Yaf_Registry::set('layout', $layout); $dispatcher->registerPlugin($layout); } }
public function _initRoute(Yaf_Dispatcher $dispatcher) { $router = $dispatcher->getRouter(); //$router->addConfig(Yaf_Registry::get("config")->routes); //$route = new Yaf_Route_Rewrite( // 'exp/:ident', // array( // 'controller' =>'index', // 'action' => 'index' // ) //); //$router -> addRoute('exp',$route); $route = new Yaf_Route_Rewrite('/admin/:action/:id', array('controller' => 'admin', 'action' => ':action')); $router->addRoute('name', $route); }
/** * 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); }*/ }
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; } }
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 = '******'; $password = '******'; $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; } }
/** * 初始化 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']); }
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); }
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); }
/** * 路由分发开始 * * @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); }
/** *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(); } }
/** * @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']); } }
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); }
function _initBase(Yaf_Dispatcher $dispatcher) { // 如果非命令行,则输出 header 头 if (!core::is_cmd()) { header("Expires: 0"); header("Cache-Control: private, post-check=0, pre-check=0, max-age=0"); header("Pragma: no-cache"); header('Content-Type: text/html; charset=UTF-8'); header('X-Powered-By: http://www.lianchuangbrothers.com/'); // 隐藏 PHP 版本 X-Powered-By: PHP/5.5.9 header('Server: Microsoft-IIS/11.11'); } //错误处理 $dispatcher->setErrorHandler([get_class($this), 'error_handler']); //添加路由协议 $dispatcher->getRouter()->addConfig((new Yaf_Config_Ini(APP_PATH . '/conf/routes.ini'))->routes); //注册本地类 Yaf_Loader::getInstance()->registerLocalNameSpace(['helper', 'misc']); // 加载数据库 Yaf_Registry::set('db', new medoo(Yaf_Registry::get("config")->get('database')->default->toArray())); //memcache //Yaf_Registry::set('memcache', new Memcache); //Yaf_Registry::get('memcache')->pconnect(Yaf_Registry::get("config")->get('memcache')->default->host, Yaf_Registry::get("config")->get('memcache')->default->port, 2.5); //redis Yaf_Registry::set('redis', new redis()); //连接redis Yaf_Registry::get('redis')->pconnect(Yaf_Registry::get("config")->get('redis')->default->host, Yaf_Registry::get("config")->get('redis')->default->port, 2.5); //redis密码 Yaf_Registry::get('redis')->auth(Yaf_Registry::get("config")->get('redis')->default->password); //使用php内置的serialize/unserialize 方法对数据进行处理 Yaf_Registry::get('redis')->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); //rediskey加前缀 Yaf_Registry::get('redis')->setOption(Redis::OPT_PREFIX, Yaf_Registry::get("config")->get('redis')->default->prefix); core::ob_start(); }