这个小框架代码放到码云上了,小伙伴们可以随便下载了 https://gitee.com/pizzzz/piz.git
该写Config了,没它不行啊。Config的功能简单,读取config目录下的配置文件。我希望能实现类似thinkphp的读取方法 ,可以读取多维数据。例如以下配置,读取方法是config('config.a.b.c').
config.php
[
'b'=>[
'c'=>'d',
],
],
]
创建frame/Lib/Config.php ,贴代码
这个类的使用方法如下:
Config::get_instance()->get('config.a.b.c');使用起来不是太方便,给它来一个更方便用的方法。
创建文件 frame/helper.php ,贴代码get($name,$default); }这样就暴露出了两个方法
- get_instance() ,可以直接调用单例模式的实例。
2.config() ,可以直接读取配置文件。把下面的代码写入 frame/base.php
define ('CONFIG_PATH',dirname (__DIR__).'/config/'); require_once PIZ_PATH."helper.php";创建配置文件 config/router.php并配置,
'index', //默认模块 'c' => 'index', //默认控制器 'a' => 'init', //默认操作 'ext' => '.html', //url后缀 例如 .html 'rules' => [ //自定义路由 'user' => 'uesr/index/init', 'login' => 'index/login/init', ] ];为了方便测试,修改下Router.php代码
public static function get_instance() { if( is_null(self::$instance) ) { self::$instance = new self(); self::$config = Config::get_instance ()->get('router'); } return self::$instance; }测试一下config。修改frame/Lib/App.php代码
public function http($request,$response){ $req = Request::get_instance (); $req->set($request); $router = Router::get_instance ()->http($req->server['request_uri']); $response->end(var_export (config('router.rules'),TRUE)); }测试运行
小伙伴们,大家看图



