本文整理汇总了PHP中Yaf_Registry::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Yaf_Registry::set方法的具体用法?PHP Yaf_Registry::set怎么用?PHP Yaf_Registry::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yaf_Registry
的用法示例。
在下文中一共展示了Yaf_Registry::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initDefaultDbAdapter
public function _initDefaultDbAdapter()
{
//新建对象
$dbAdapter = new Zend\Db\Adapter\Adapter(Yaf_Application::app()->getConfig()->mysql->write->toArray());
//设为全局变量
Yaf_Registry::set("db", $dbAdapter);
}
示例2: _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());
}
}
示例3: loadDatabase
protected function loadDatabase($name)
{
$database = Yaf_Registry::get('_database');
if (isset($database[$name])) {
return $database[$name];
}
$config = Yaf_Registry::get('_config');
if (isset($config->database->{$name})) {
if (is_null($database)) {
$database = array();
}
$dbConfig = $config->database->{$name};
$pdoParams = array();
if ($dbConfig->pconnect) {
$pdoParams[Db::ATTR_PERSISTENT] = TRUE;
}
try {
$conn = new Db($dbConfig->type . ':host=' . $dbConfig->host . '; dbname=' . $dbConfig->database, $dbConfig->username, $dbConfig->password, $pdoParams);
} catch (PDOException $error) {
throw new Exception($error->getMessage(), 500);
}
$database[$name] = $conn;
Yaf_Registry::set('_database', $database);
return $conn;
} else {
throw new Exception('Undefined database', 500);
}
}
示例4: 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);
}*/
}
示例5: _initDatabase
public function _initDatabase()
{
$servers = array();
$database = $this->config->database;
$servers[] = $database->master->toArray();
$slaves = $database->slaves;
if (!empty($slaves)) {
$slave_servers = explode('|', $slaves->servers);
$slave_users = explode('|', $slaves->users);
$slave_passwords = explode('|', $slaves->passwords);
$slave_databases = explode('|', $slaves->databases);
$slaves = array();
foreach ($slave_servers as $key => $slave_server) {
if (isset($slave_users[$key]) && isset($slave_passwords[$key]) && isset($slave_databases[$key])) {
$slaves[] = array('server' => $slave_server, 'user' => $slave_users[$key], 'password' => $slave_passwords[$key], 'database' => $slave_databases[$key]);
}
}
$servers[] = $slaves[array_rand($slaves)];
}
Yaf_Registry::set('database', $servers);
if (isset($database->mysql_cache_enable) && $database->mysql_cache_enable && !defined('MYSQL_CACHE_ENABLE')) {
define('MYSQL_CACHE_ENABLE', true);
}
if (isset($database->mysql_log_error) && $database->mysql_log_error && !defined('MYSQL_LOG_ERROR')) {
define('MYSQL_LOG_ERROR', true);
}
Yaf_Loader::import(APPLICATION_PATH . '/library/Db/Db.php');
Yaf_Loader::import(APPLICATION_PATH . '/library/Db/DbQuery.php');
}
示例6: init
public static function init()
{
$_ENV['APP_NAME'] = pathinfo(realpath(APPLICATION_PATH), PATHINFO_BASENAME);
$configurePath = sprintf('%s/../config/config.ini', APPLICATION_PATH);
$config = new Yaf_Config_Ini($configurePath, 'production');
Yaf_Registry::set('dbconfig', $config);
self::loadEssentials();
}
示例7: _initZendDb
public function _initZendDb(Yaf_Dispatcher $dispatcher)
{
$arrConfig = Yaf_Application::app()->getConfig();
$zendDb = new Zend_Db();
$params = array('host' => $arrConfig->mysql->read->host, 'username' => $arrConfig->mysql->read->username, 'password' => $arrConfig->mysql->read->password, 'dbname' => $arrConfig->mysql->read->dbname, 'port' => $arrConfig->mysql->read->port);
$db = $zendDb->factory('PDO_MYSQL', $params);
Yaf_Registry::set('db', $db);
}
示例8: _initPlugin
public function _initPlugin(Yaf_Dispatcher $dispatcher)
{
$router = new RouterPlugin();
$dispatcher->registerPlugin($router);
$admin = new AdminPlugin();
$dispatcher->registerPlugin($admin);
Yaf_Registry::set('adminPlugin', $admin);
}
示例9: _initConfig
public function _initConfig()
{
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
// 关闭自动加载模板
//把配置保存起来
$arrConfig = Yaf_Application::app()->getConfig();
Yaf_Registry::set('config', $arrConfig);
}
示例10: _initRedis
/**
* Init Redis
*/
public function _initRedis(Yaf_Dispatcher $dispatcher)
{
$config = Yaf_Application::app()->getConfig();
$redis = new Redis();
$redis->connect($config['redis_host'], $config['redis_port']);
Yaf_Registry::set('redis', $redis);
// TODO sms Redis queue
//Yaf_Registry::set('redis_queue_sms', $config['redis_queue_sms']);
}
示例11: _initConfig
public function _initConfig(Yaf_Dispatcher $dispatcher)
{
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
$sysConfig = (include APP_PATH . "/conf/config.php");
Yaf_Registry::set("sysConfig", $sysConfig);
$dispatcher->autoRender(FALSE);
//全局关闭渲染
}
示例12: __construct
public function __construct()
{
$this->__application = Yaf_Registry::get('Application');
if ($this->__application == null) {
$this->__application = new Yaf_Application(ROOT_PATH . "/conf/application.ini");
Yaf_Registry::set('Application', $this->__application);
Yaf_Registry::set('config', $this->__application->getConfig());
}
}
示例13: _initView
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');
}
示例14: _initSession
/**
* 初始化SESSION
*
* @param Yaf_Dispatcher $dispatcher
*/
public function _initSession(Yaf_Dispatcher $dispatcher)
{
//开启SESSION
session_name('GITHUBLOG_SID');
session_start();
//获取用户UID
$uid = \Comm\Arg::session('uid', FILTER_VALIDATE_INT);
Yaf_Registry::set('current_uid', $uid);
}
示例15: getAPPConfig
private function getAPPConfig()
{
$key = __METHOD__;
$config = Yaf_Registry::get($key);
if ($config == null) {
$config = Yaf_Application::app() == null ? new Yaf_Application(APPLICATION_CONFIG_PATH . '/application.ini') : Yaf_Application::app();
Yaf_Registry::set($key, $config);
}
return $config;
}