當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Yaf_Application::app方法代碼示例

本文整理匯總了PHP中Yaf_Application::app方法的典型用法代碼示例。如果您正苦於以下問題:PHP Yaf_Application::app方法的具體用法?PHP Yaf_Application::app怎麽用?PHP Yaf_Application::app使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Yaf_Application的用法示例。


在下文中一共展示了Yaf_Application::app方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _init

 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());
     }
 }
開發者ID:a707937337,項目名稱:helloword,代碼行數:30,代碼來源:Bootstrap.php

示例2: 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;
     }
 }
開發者ID:290329416,項目名稱:guahao,代碼行數:30,代碼來源:Error.php

示例3: _initConfig

 /**
  * 把配置存到注冊表
  */
 function _initConfig()
 {
     Yaf_Registry::set("config", $config = Yaf_Application::app()->getConfig());
     define('PATH_APP', $config->application->directory);
     define('PATH_TPL', PATH_APP . '/views');
     define('USER_IP', Tool_Fnc::realip());
 }
開發者ID:tanqinwang,項目名稱:test_own,代碼行數:10,代碼來源:Bootstrap.php

示例4: connect

 /**
  * Connect to MySQL [Support read/write splitting]
  *
  * @param string => use default DB if parameter is not specified !
  * @return NULL
  */
 private function connect($type = 'WRITE')
 {
     $config = Yaf_Application::app()->getConfig();
     $db = $config['Default'];
     $driver = $config['TYPE'];
     $host = $config[$type . '_HOST'];
     $port = $config[$type . '_PORT'];
     $user = $config[$type . '_USER'];
     $pswd = $config[$type . '_PSWD'];
     if (!$port) {
         $port = 3306;
     }
     $dsn = $driver . ':host=' . $host . ';port=' . $port . ';dbname=' . $db;
     try {
         if (!self::$obj[$type]) {
             self::$conn = self::$obj[$type] = new PDO($dsn, $user, $pswd);
             self::$conn->query('SET NAMES utf8');
             unset($db, $driver, $host, $port, $user, $pswd, $dsn);
         }
     } catch (PDOException $e) {
         if (ENV == 'DEV') {
             Helper::raiseError(debug_backtrace(), $e->getMessage());
         } else {
             file_put_contents($this->logFile, $e->getMessage() . PHP_EOL, FILE_APPEND);
         }
     }
 }
開發者ID:udeth,項目名稱:YOF,代碼行數:33,代碼來源:M_Model.pdo.php

示例5: _generateShare

 private function _generateShare($url)
 {
     $config = Yaf_Application::app()->getConfig();
     $appID = $config['wx_appID'];
     $appSecret = $config['wx_appSecret'];
     $share['appID'] = $appID;
     $share['timestamp'] = CUR_TIMESTAMP;
     $share['nonceStr'] = 'Wu5WZYThz1wzccnX';
     $share['link'] = $url;
     // 驗證 ticket 是否失效
     $m_ticket = $this->load('Ticket');
     $ticket = $m_ticket->SelectOne();
     $gap = CUR_TIMESTAMP - $ticket['addTime'];
     if (!$ticket['ticket'] || $gap > 7200) {
         // Get token
         $token = $this->_getToken($appID, $appSecret);
         // Get ticket
         $ticket = $this->_getTicket($token);
         if ($ticket) {
             $jsapi_ticket = $m['ticket'] = $ticket;
             $m['addTime'] = CUR_TIMESTAMP;
             $where = 1;
             $m_ticket->Delete($where);
             $m_ticket->Insert($m);
         }
     } else {
         $jsapi_ticket = $ticket['ticket'];
     }
     // Get signature
     $string1 = 'jsapi_ticket=' . $jsapi_ticket . '&noncestr=' . $share['nonceStr'];
     $string1 .= '&timestamp=' . $share['timestamp'] . '&url=' . $url;
     $share['signature'] = sha1($string1);
     return $share;
 }
開發者ID:xujunjiepk,項目名稱:YOF,代碼行數:34,代碼來源:Weixin.php

示例6: routerShutdown

 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     //pr($request);
     $modules = Yaf_Application::app()->getModules();
     $uri = $request->getRequestUri();
     $uriInfo = explode('/', $uri);
     $module = ucfirst($uriInfo[1]);
     $controller = $uriInfo[2];
     $action = $uriInfo[3];
     if (!in_array($module, $modules)) {
         $module = 'index';
         $controller = $uriInfo[1];
         $action = $uriInfo[2];
     }
     $request->setModuleName(ucfirst($module));
     if (!$controller) {
         $controller = 'index';
     }
     $request->setControllerName(ucfirst($controller));
     if (!$action) {
         $action = 'index';
     }
     $request->setActionName($action);
     //pr($request);
 }
開發者ID:pan269,項目名稱:YOF,代碼行數:25,代碼來源:Router.php

示例7: __construct

 public function __construct()
 {
     $config = Yaf_Application::app()->getConfig();
     Yaf_Loader::import('L_Wechat');
     $options = array('token' => self::WX_TOKEN, 'appid' => $config['wx_appID'], 'appsecret' => $config['wx_appsecret'], 'access_token' => $config['wx_access_token'], 'expires' => $config['wx_expires']);
     $this->wxSDK = new L_Wechat($options);
 }
開發者ID:GobYang,項目名稱:thaidh,代碼行數:7,代碼來源:Com_Weixin.php

示例8: _initPlugin

 public function _initPlugin(Yaf_Dispatcher $dispatcher)
 {
     // set include paths of the system.
     set_include_path(get_include_path() . PATH_SEPARATOR . Yaf_Loader::getInstance()->getLibraryPath());
     /* register a billrun plugin system from config */
     $config = Yaf_Application::app()->getConfig();
     if (isset($config->plugins)) {
         $plugins = $config->plugins->toArray();
         $dispatcher = Billrun_Dispatcher::getInstance();
         foreach ($plugins as $plugin) {
             Billrun_Log::getInstance()->log("Load plugin " . $plugin, Zend_log::DEBUG);
             $dispatcher->attach(new $plugin());
         }
     }
     if (isset($config->chains)) {
         $chains = $config->chains->toArray();
         $dispatcherChain = Billrun_Dispatcher::getInstance(array('type' => 'chain'));
         foreach ($chains as $chain) {
             Billrun_Log::getInstance()->log("Load plugin " . $chain, Zend_log::DEBUG);
             $dispatcherChain->attach(new $chain());
         }
     }
     // make the base action auto load (required by controllers actions)
     Yaf_Loader::getInstance(APPLICATION_PATH . '/application/helpers')->registerLocalNamespace('Action');
 }
開發者ID:kalburgimanjunath,項目名稱:system,代碼行數:25,代碼來源:Bootstrap.php

示例9: __construct

 public function __construct()
 {
     $config = Yaf_Application::app()->getConfig();
     Yaf_Loader::import('L_Wechat.class.php');
     $options = array('token' => $config['wx_token'], 'appid' => $config['wx_appID'], 'appsecret' => $config['wx_appSecret']);
     $this->wxSDK = new L_Wechat($options);
 }
開發者ID:xujunjiepk,項目名稱:YOF,代碼行數:7,代碼來源:Com_Weixin.php

示例10: callbackAction

 public function callbackAction()
 {
     $mediaqqmodel = new Media_QQModel($this->_basemodel, $this->_qqparam);
     $app_id = isset($_REQUEST['app_id']) ? trim($_REQUEST['app_id']) : '69948denMVMoBujYGLSFGUHbkvP7E3';
     $mediaqq = $mediaqqmodel->getApp($app_id);
     $APPID = $mediaqq['APPID'] && $mediaqq['APPKEY'] ? $mediaqq['APPID'] : $mediaqq['def_APPID'];
     $APPKEY = $mediaqq['APPID'] && $mediaqq['APPKEY'] ? $mediaqq['APPKEY'] : $mediaqq['def_APPKEY'];
     $redirect_uri = $this->_qqparam['redirect_uri'] . '?app_id=' . $mediaqq['app_id'];
     $state = md5($mediaqq['app_key']);
     $qcinit = new QQAPI_YafQQConnetAPI();
     $qc = new QC();
     $access_token = $qc->qq_callback($APPID, $redirect_uri, $APPKEY);
     echo $access_token . '----------';
     $openid = $qc->get_openid($access_token);
     echo $openid . '---------';
     $qqUser = $qc->my_get_userinfo($access_token, $openid, $APPID);
     if ($qqUser && $qqUser->nickname) {
         $media_user_id = $mediaqqmodel->saveUser($openid, $qqUser, $APPID);
         if ($media_user_id) {
             $usertokentime = date('Y-m-d H:i:s', time() + Yaf_Application::app()->getConfig()->application->usertokentime);
             $login_token = $mediaqqmodel->saveAccessToken($app_id, $access_token, $openid, $media_user_id, $usertokentime);
             if ($login_token) {
                 $url = $mediaqq['token_url'];
                 $concat = '&';
                 if (strpos($url, '?') === false) {
                     $concat = '?';
                 }
                 $url .= $concat . "token={$login_token}";
                 header("Location:{$url}");
             }
         }
     }
     exit;
 }
開發者ID:pbchen,項目名稱:thirdLoginAPI,代碼行數:34,代碼來源:Qq.php

示例11: _initSmarty

 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);
 }
開發者ID:gangjun911,項目名稱:yaf-examples,代碼行數:7,代碼來源:Bootstrap.php

示例12: _initDefaultDbAdapter

 public function _initDefaultDbAdapter()
 {
     //新建對象
     $dbAdapter = new Zend\Db\Adapter\Adapter(Yaf_Application::app()->getConfig()->mysql->write->toArray());
     //設為全局變量
     Yaf_Registry::set("db", $dbAdapter);
 }
開發者ID:nameNotNull,項目名稱:Yaf_zendDb,代碼行數:7,代碼來源:bootstrap.php

示例13: _initConfig

 public function _initConfig()
 {
     //把配置保存起來
     $this->arrConfig = Yaf_Application::app()->getConfig();
     $arrConfig = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('config', $arrConfig);
 }
開發者ID:Wen1750686723,項目名稱:yafdemo,代碼行數:7,代碼來源:Bootstrap.php

示例14: routerShutdown

 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $modules = Yaf_Application::app()->getModules();
     $uri = $request->getRequestUri();
     $uriInfo = explode('/', $uri);
     $module = ucfirst($uriInfo[1]);
     if (!in_array($module, $modules)) {
         $module = 'index';
         // 由於 YAF 源碼隻不支持大小寫混寫的控製器和 Action名, 這裏來滿足
         if ($request->controller) {
             if (strtoupper($request->controller) == strtoupper($uriInfo[1])) {
                 $controller = ucfirst($uriInfo[1]);
                 $request->setControllerName($controller);
             }
         }
         if ($request->action) {
             if (strtoupper($request->action) == strtoupper($uriInfo[2])) {
                 $request->setActionName($uriInfo[2]);
             }
         }
     } else {
         $request->setModuleName($module);
         $request->setControllerName(ucfirst($uriInfo[2]));
         $action = $uriInfo[3];
         if (!$action) {
             $action = 'index';
         }
         $request->setActionName($action);
     }
     //pr($request);
 }
開發者ID:xujunjiepk,項目名稱:YOF,代碼行數:31,代碼來源:Router.php

示例15: init

 /**
  * 初始化函數
  * 1、時區設置
  * 2、數據庫連接配置
  */
 public function init()
 {
     header("Content-type: application/json; charset=utf-8");
     ini_set('date.timezone', 'Asia/Shanghai');
     //獲取數據庫連接信息
     $this->_db = Base_Db::getInstance(Yaf_Application::app()->getConfig()->application->db->toArray());
     $this->_basemodel = new BasedbModel($this->_db);
 }
開發者ID:pbchen,項目名稱:thirdLoginAPI,代碼行數:13,代碼來源:User.php


注:本文中的Yaf_Application::app方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。