【微擎】ThinkPHP框架开发微擎应用?

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();
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值