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


PHP Config::set方法代碼示例

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


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

示例1: testFill

 public function testFill()
 {
     $model = new Model('', $this->getConfig());
     $data = ['username' => '', 'nickname' => 'nickname', 'phone' => ' 123456', 'hobby' => ['1', '2'], 'cityid' => '1', 'a' => 'a', 'b' => 'b'];
     $auto = ['user' => ['__option__' => ['value_fill' => 'username,password,phone', 'exists_fill' => 'nickname'], 'username' => ['strtolower', 'callback'], 'password' => ['md5', 'callback'], 'nickname' => [[&$this, 'fillName'], 'callback', 'cn_'], 'phone' => function ($value, $data) {
         return trim($value);
     }, 'hobby' => ['', 'serialize'], 'cityid' => ['1', 'ignore'], 'address' => ['address'], 'integral' => 0, ['reg_time', 'time', 'callback'], ['login_time', function ($value, $data) {
         return $data['reg_time'];
     }], 'ab' => ['a,b', 'serialize']]];
     \think\Config::set('auto', $auto);
     $result = $model->auto('user')->create($data);
     $data['nickname'] = 'cn_nickname';
     $data['phone'] = '123456';
     $data['hobby'] = serialize($data['hobby']);
     $data['address'] = 'address';
     $data['integral'] = 0;
     $data['reg_time'] = time();
     $data['login_time'] = $data['reg_time'];
     $data['ab'] = serialize(['a' => 'a', 'b' => 'b']);
     unset($data['cityid'], $data['a'], $data['b']);
     $this->assertEquals($data, $result);
     // 測試帶.和*的鍵名
     $data = ['name' => ['a' => 'a', 'b' => 'b'], 'goods' => [0 => [0 => ['item' => 'item', 'price' => ''], 1 => ['item' => 'item2', 'price' => '']]]];
     $test = ['name.*' => 'name', 'goods.*.*.price' => 100];
     $result = $model->auto($test)->create($data);
     $data['name']['a'] = $data['name']['b'] = 'name';
     $data['goods'][0][0]['price'] = 100;
     $data['goods'][0][1]['price'] = 100;
     $this->assertEquals($data, $result);
 }
開發者ID:Lofanmi,項目名稱:think,代碼行數:30,代碼來源:modelTest.php

示例2: C

function C($name = '', $value = null, $range = '')
{
    if (is_null($value) && is_string($name)) {
        return \think\Config::get($name, $range);
    } else {
        return \think\Config::set($name, $value, $range);
    }
}
開發者ID:yuhongjie,項目名稱:think,代碼行數:8,代碼來源:helper.php

示例3: set_theme

 protected function set_theme($name)
 {
     $tmp = Config::get('template');
     if ($name) {
         $tmp['view_path'] = realpath(APP_PATH . '../public/themes/' . $name) . DS;
     } else {
         $tmp['view_path'] = "";
     }
     Config::set('template', $tmp);
 }
開發者ID:samplecms,項目名稱:tp5_theme,代碼行數:10,代碼來源:Theme.php

示例4: testConfig

 public function testConfig()
 {
     App::run(Config::get());
     Config::parse('isTrue=1', 'test');
     Config::range('test');
     $this->assertTrue(Config::has('isTrue'));
     $this->assertEquals(1, Config::get('isTrue'));
     Config::set('isTrue', false);
     $this->assertEquals(0, Config::get('isTrue'));
     Config::reset();
 }
開發者ID:guozqiu,項目名稱:think,代碼行數:11,代碼來源:configTest.php

示例5: testConfig

 public function testConfig()
 {
     App::run();
     $this->assertTrue(Config::has('url_route_on'));
     $this->assertEquals(1, Config::get('url_route_on'));
     Config::set('url_route_on', false);
     $this->assertEquals(0, Config::get('url_route_on'));
     Config::range('test');
     $this->assertFalse(Config::has('url_route_on'));
     Config::reset();
 }
開發者ID:lw78665806,項目名稱:think,代碼行數:11,代碼來源:configTest.php

示例6: __construct

 /**
  * 架構函數
  * 遍曆合並Config
  *
  * @return void
  */
 public function __construct()
 {
     if (!empty($this->options)) {
         foreach ($this->options as $name => $val) {
             // 參數已設置 則覆蓋行為參數
             if (Config::get($name) !== null) {
                 $this->options[$name] = C($name);
             } else {
                 Config::set($name, $val);
             }
         }
         array_change_key_case($this->options);
     }
 }
開發者ID:minowu,項目名稱:smartthink,代碼行數:20,代碼來源:Behavior.php

示例7: testDetect

 public function testDetect()
 {
     Config::set('lang_list', ['zh-cn', 'zh-tw']);
     Lang::set('hello', '歡迎', 'zh-cn');
     Lang::set('hello', '歡迎', 'zh-tw');
     Config::set('lang_detect_var', 'lang');
     Config::set('lang_cookie_var', 'think_cookie');
     $_GET['lang'] = 'zh-tw';
     Lang::detect();
     $this->assertEquals('歡迎', Lang::get('hello'));
     $_GET['lang'] = 'zh-cn';
     Lang::detect();
     $this->assertEquals('歡迎', Lang::get('hello'));
 }
開發者ID:top-think,項目名稱:framework,代碼行數:14,代碼來源:langTest.php

示例8: testRun

 public function testRun()
 {
     Config::set('root_namespace', ['/path/']);
     App::run();
     $expectOutputString = '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一劍 - 為API開發設計的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛雲</a> 獨家讚助發布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>';
     $this->expectOutputString($expectOutputString);
     $rc = new ReflectionClass('\\think\\Loader');
     $ns = $rc->getProperty('namespace');
     $ns->setAccessible(true);
     $this->assertEquals(true, in_array('/path/', $ns->getValue()));
     $this->assertEquals(true, function_exists('L'));
     $this->assertEquals(true, function_exists('C'));
     $this->assertEquals(true, function_exists('I'));
     $this->assertEquals(Config::get('default_timezone'), date_default_timezone_get());
 }
開發者ID:cnzin,項目名稱:think,代碼行數:15,代碼來源:appTest.php

示例9: load

 /**
  * 加載係統擴展配置
  */
 public static function load()
 {
     $config = \think\Cache::get('db_config_cache_data');
     if (!$config) {
         // 在這裏先判斷一下數據庫是否已經正確安裝
         $Db = \think\Loader::db();
         $Query = $Db->query("SHOW TABLES LIKE '" . \think\Config::get('database.prefix') . "config'");
         if (empty($Query)) {
             self::install();
         }
         $data = \think\Db::name('Config')->where('status', 1)->field('type,name,value')->select();
         $config = [];
         if ($data && is_array($data)) {
             foreach ($data as $value) {
                 $config[$value['name']] = self::parse($value['type'], $value['value']);
             }
         }
         \think\Cache::set('db_config_cache_data', $config);
     }
     \think\Config::set($config);
 }
開發者ID:cjango,項目名稱:cwms,代碼行數:24,代碼來源:Config.php

示例10: C

/**
 * 重寫C方法,改為引用Config方法
 *
 * @param string $name
 */
function C($name = null, $value = null)
{
    // 無參數時獲取所有
    if (empty($name)) {
        return Config::getAll();
    }
    // 字符串,為空則獲取
    if (is_string($name) && is_null($value)) {
        return Config::get($name);
    }
    // 字符串,不為空則單個設置
    if (is_string($name) && !is_null($value)) {
        return Config::set($name, $value);
    }
    // 數組設置
    if (is_array($name)) {
        return Config::setAll($name);
    }
    // 避免非法參數
    Debug::throw_exception('C funtion error!');
}
開發者ID:minowu,項目名稱:smartthink,代碼行數:26,代碼來源:functions.php

示例11: testFill

 public function testFill()
 {
     $data = ['username' => '', 'nickname' => 'nickname', 'phone' => ' 123456', 'hobby' => ['1', '2'], 'cityid' => '1', 'a' => 'a', 'b' => 'b'];
     $auto = ['user' => ['__option__' => ['value_fill' => ['username', 'password', 'phone'], 'exists_fill' => 'nickname'], 'username' => ['strtolower', 'callback'], 'password' => ['md5', 'callback'], 'nickname' => [[&$this, 'fillName'], 'callback', 'cn_'], 'phone' => function ($value, $data) {
         echo $value;
         return trim($value);
     }, 'ab' => ['a,b', 'serialize'], 'cityid' => ['1', 'ignore'], 'address' => ['address'], 'integral' => 0, ['reg_time', 'time', 'callback'], ['login_time', function ($value, $data) {
         return $data['reg_time'];
     }]]];
     Config::set('auto', $auto);
     $result = Validate::fill($data, 'user');
     $data['nickname'] = 'cn_nickname';
     $data['phone'] = '123456';
     $data['ab'] = serialize(['a' => 'a', 'b' => 'b']);
     $data['address'] = 'address';
     $data['integral'] = 0;
     $data['reg_time'] = time();
     $data['login_time'] = $data['reg_time'];
     unset($data['cityid'], $data['a'], $data['b']);
     $this->assertEquals($data, $result);
 }
開發者ID:Aoiujz,項目名稱:think,代碼行數:21,代碼來源:validateTest.php

示例12: testVar

 public function testVar()
 {
     Config::set('app_multi_module', true);
     $request = new Request();
     $request->route(['name' => 'thinkphp', 'id' => 6]);
     $request->get(['id' => 10]);
     $request->post(['id' => 8]);
     $request->put(['id' => 7]);
     $request->request(['test' => 'value']);
     $this->assertEquals(['name' => 'thinkphp', 'id' => 6], $request->route());
     //$this->assertEquals(['id' => 10], $request->get());
     $this->assertEquals('thinkphp', $request->route('name'));
     $this->assertEquals('default', $request->route('test', 'default'));
     $this->assertEquals(10, $request->get('id'));
     $this->assertEquals(0, $request->get('ids', 0));
     $this->assertEquals(8, $request->post('id'));
     $this->assertEquals(7, $request->put('id'));
     $this->assertEquals('value', $request->request('test'));
     $this->assertEquals('thinkphp', $request->param('name'));
     $this->assertEquals(6, $request->param('id'));
     $this->assertFalse($request->has('user_id'));
     $this->assertTrue($request->has('test', 'request'));
     $this->assertEquals(['id' => 6], $request->only('id'));
     $this->assertEquals(['name' => 'thinkphp', 'lang' => 'zh-cn'], $request->except('id'));
     $this->assertEquals('THINKPHP', $request->param('name', '', 'strtoupper'));
 }
開發者ID:top-think,項目名稱:framework,代碼行數:26,代碼來源:requestTest.php

示例13: testBuildAnchor

 public function testBuildAnchor()
 {
     Route::get('blog/:id', 'index/blog');
     Config::set('url_html_suffix', 'shtml');
     $this->assertEquals('/blog/10.shtml#detail', Url::build('/blog/10#detail'));
 }
開發者ID:Lofanmi,項目名稱:think,代碼行數:6,代碼來源:urlTest.php

示例14: defined

defined('CONF_EXT') or define('CONF_EXT', EXT);
// 配置文件後綴
defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_');
// 環境變量的配置前綴
// 環境常量
define('IS_CLI', PHP_SAPI == 'cli' ? true : false);
define('IS_WIN', strpos(PHP_OS, 'WIN') !== false);
// 載入Loader類
require CORE_PATH . 'Loader.php';
// 加載環境變量配置文件
if (is_file(ROOT_PATH . '.env')) {
    $env = parse_ini_file(ROOT_PATH . '.env', true);
    foreach ($env as $key => $val) {
        $name = ENV_PREFIX . strtoupper($key);
        if (is_array($val)) {
            foreach ($val as $k => $v) {
                $item = $name . '_' . strtoupper($k);
                putenv("{$item}={$v}");
            }
        } else {
            putenv("{$name}={$val}");
        }
    }
}
// 注冊自動加載
\think\Loader::register();
// 注冊錯誤和異常處理機製
\think\Error::register();
// 加載慣例配置文件
\think\Config::set(include THINK_PATH . 'convention' . EXT);
開發者ID:pangPython,項目名稱:iNewsCMS,代碼行數:30,代碼來源:base.php

示例15: setUp

 protected function setUp()
 {
     Config::set('app_multi_module', true);
 }
開發者ID:samplecms,項目名稱:framework,代碼行數:4,代碼來源:routeTest.php


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