PHP code example of varimax / app
1. Go to this page and download the library: Download varimax/app 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/ */
varimax / app example snippets
//公共组
Router::group( ['id' => 'public', 'prefix' => '/', 'namespace' => 'App\Controller'], function () {
Router::any('/', 'Index@index');
Router::any('/test')->call('Test@index');
Router::any('/test/(list:*)/(id:\d+)' )->call('Test@test' );
Router::get('/test/(shop:vip|user)' )->call('Test@shop' ); //only allow vip or user string
Router::get('/test/(shop:vip|user)/(id:|\d+)' )->call('Test@shop' );
});
/**
* 验证组
* @param id 组id
* @param prefix 组前缀
* @param namespace 组命名空间
* @param pipeline 组中间件
*/
Router::group( ['id' => 'permit', 'prefix' => '/', 'namespace' => 'App\Controller', 'pipeline' => [\App\Pipeline\Auth::class,\App\Pipeline\Cors::class]], function () {
//首页
Router::get('/home')->call('Home@index');
/**
* 会员中心
* name: 组名称
* prefix: 当以/开头表示覆盖前缀,否则继承
* namespace: 当以\开头表示覆盖命名空间前缀,否则继承
*/
Router::group(['name'=>'user', 'prefix'=>'/user', 'namespace'=>'User', 'pipeline'=>'App\Pipeline\User'], function(){
Router::get('/list')->call('User@index');
Router::any('/create')->call('User@create');
Router::any('/update')->call('User@update');
Router::any('/delete')->call('User@delete');
});
} );