ThinkPHP框架开发微擎应用?
TP5.1
微擎中的site.php
/** * * Class YcModuleSite */class YcModuleSite extends WeModuleSite {public function __call($name, $arguments){include __DIR__.'/public/index.php';exit;}}
ThinkPHP5.1中的index.php
<?php// [ 应用入口文件 ]namespace think;global $_W,$_GPC;//设置模块名称defined('MODULE_NAME') or define('MODULE_NAME',$_GPC['m']);//获取微擎中的do参数,相当于TP中的module$mod = $_GPC['do'] ? $_GPC['do'] : 'index';//获取微擎链接中的opt参数,相当于TP中的controller参数名称$opt = isset($_GPC['opt']) ? $_GPC['opt'] : 'index';$_GPC['opt'] = $opt = strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $opt), "_"));//获取微擎链接中的act参数,相当于TP中的action参数名称$act = isset($_GPC['act']) ? trim($_GPC['act']) : 'index';// 加载基础文件require __DIR__ . '/../framework/base.php';// 支持事先使用静态方法设置Request对象和Config对象// 执行应用并响应Container::get('app')->path(dirname(__DIR__) . '/application/')->bind("{$mod}/{$opt}/{$act}")->run()->send();
TP5.0
微擎中的site.php
/** * * Class YcModuleSite */class YcModuleSite extends WeModuleSite {public function __call($name, $arguments){include __DIR__.'/public/index.php';exit;}}
ThinkPHP5.0中的index.php
<?php// [ 应用入口文件 ]namespace think;global $_GPC;//设置头部,防止跨域header("Access-Control-Allow-Origin:*");//设置模块名称defined('MODULE_NAME') or define('MODULE_NAME',$_GPC['m']);defined('WEB_PATH') or define( 'WEB_PATH' , __DIR__ . '/');defined('APP_PATH') or define( 'APP_PATH' , dirname(__DIR__ ) . '/application/');defined('RUNTIME_PATH') or define( 'RUNTIME_PATH' , IA_ROOT . '/data/runtime/');//获取微擎中的do参数,相当于TP中的module$mod = isset($_GPC['do']) ? $_GPC['do'] : 'index';//获取微擎链接中的opt参数,相当于TP中的controller参数名称$opt = isset($_GPC['opt']) ? $_GPC['opt'] : 'index';$_GPC['opt'] = $opt = strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $opt), "_"));//获取微擎链接中的act参数,相当于TP中的action参数名称$act = isset($_GPC['act']) ? trim($_GPC['act']) : 'index';// 加载基础文件require dirname(__DIR__ ) . '/framework/base.php';// 支持事先使用静态方法设置Request对象和Config对象// 2. 执行应用define('BIND_MODULE',"{$mod}/{$opt}/{$act}");App::run()->send();