PHP code example of waiterphp / core

1. Go to this page and download the library: Download waiterphp/core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

waiterphp / core example snippets


$configs = load_configs($fileNames);

set_env('app_name', 'waiterphp_core');
print get_env('app_name');

set_env('database.default.username', 'test');
set_env('database', [
	'default'=>[
		'username'=>'test'
	]
]);

set_env(['database'=>['default'=>[
	'host'=>'localhost',
	'username'=>'root',
	'password'=>'',
	'database'=>'tests'
]]])

// 设置数据库配置,可通过load_configs从文件直接装载
set_env('database.default', [
	'host'=>'127.0.0.1', 
	'username'=>'root', 
	'password'=>'', 
	'database'=>'tests'
]);

// 获取多行数据
$data = table('article')->select('articleId,userId,title,hit as hit_num')
->where([
	'userId'=>1,
	'articleId'=>[1,2,3,4,5,6,7,8],
	'addTime >='=>'2018-01-01 00:00:00',
	'title like'=>'%测试%'
])->orderBy('articleId desc')
->limit(10)
->offset(0)->fetchAll();

// 获取单行
$data = table('article')->where(['userId'=>1])->fetchRow();

// 写入数据
$articleId = table('article')->insert([
	'userId'=>2,
	'title'=>'insert data'
]);

// 删除数据
table('article')->where([
	'articleId'=>$articleId
])->delete();

// 更新数据
table('article')->where([
	'articleId'=>1
])->update([
	'hit'=>211
]);

// 表达式更新
 table('article')->where([
	'articleId'=>1
])->update([
	'hit=hit+1'
]);

// 统计 
table('article')->where(['userId'=>1])->count();

// 分组
table('article')->select('userId,count(*)')->groupBy('userId')->fetchAll();

//file


// redis
set_env('cache.redis', []);
cache('redis')->hmget('some_key');

// memcache


set_env('view', []);
echo render('user/login.html', ['username'=>'测试'], 'smarty');

set_env('view', []);
render('user/login.html', ['username'=>'测试'], 'tools.myView');

use waiterphp\core\Filter\FilterTrait;

class HttpRequest
{
	use Filter;
}

filter($data)->getInt('userId', '');

assert_exception(false, '程序异常!', 500);

bind_to_env($tab, $action);
env_trigger($tab, $params = []);

build();

print request()->hostname();
print request()->query();
print request()->query('userId');
print request()->post();
print request()->post('userId');

curl($url, $params, $httpType, $header);

get_files('/home/user');
write('/home/user/test.txt', $content, 'a+');