当前位置: 首页>>代码示例>>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;未经允许,请勿转载。