PHP code example of silangtech / silangphp

1. Go to this page and download the library: Download silangtech/silangphp 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/ */

    

silangtech / silangphp example snippets


\SilangPHP\Route::addGroup('silangphp', function(){
    \SilangPHP\Route::addRoute('GET', 'index', '\\App\\Controller\\IndexController@Index');
});


\SilangPHP\Route::use(funciton($c){
    // 逻辑前
    $c->next();
    // 逻辑后
});


Class index{
    // 一定要加$c参数,主要返回相关的context
    public function index($c)
    {
        
    }
}

public function index($c)
{
    $c->request->item('test', '');
    $c->request->get('test', '');
    $c->request->post('test', '');
    $c->JSON(200, ['array' => 'test']);
    $c->String(200, '哈哈');
}

// 定义好与vendor同目录即可,加载composer使用
define("PS_ROOT_PATH",       dirname(dirname(__FILE__)));
// 设置你自己的Config路径, 不然读取不了Config
define("PS_CONFIG_PATH",     PS_ROOT_PATH."/Config/");
// 设置你项目的tmp路径
define("PS_RUNTIME_PATH",	 PS_ROOT_PATH."/Runtime/");
//  加载composer

// 定义好与vendor同目录即可,加载composer使用
define("PS_ROOT_PATH",       dirname(dirname(__FILE__)));
// 设置你自己的Config路径, 不然读取不了Config
define("PS_CONFIG_PATH",     PS_ROOT_PATH."/Config/");
// 设置你项目的tmp路径
define("PS_RUNTIME_PATH",	 PS_ROOT_PATH."/Runtime/");

public function index($c)
{
    $params = ['title' => '首页标题', 'body' => '这是一篇文章'];
    $c->HTML(200, '/web/index.php', $params);
}


\SilangPHP\SilangPHP::setCache('key', 'test');
\SilangPHP\SilangPHP::getCache('key');

$data = scandir($path);
// scan之后,把controll读取生成Route配置
// 处理control文件略过
echo "Route::addRoute('POST', '/api/{$classname}/{$funcname}{$vars}', 'mg\\\\http\\\\api\\\\controller\\\\{$classname}@{$funcname}');".PHP_EOL;


\App\Router::initialize();
\SilangPHP\SilangPHP::engine(dirname(dirname(__FILE__)));
\SilangPHP\SilangPHP::$http = 2;
\SilangPHP\SilangPHP::run("8081");