微擎:app是MVC架构时,将封面链接导向指定的do,op,ac

1.首先要在模块的封面管理处,添加触发关键字


此时你会发现,直接的URL,只会是这样:

http://127.0.0.1/WeEngine0.7Release/app/index.php?i=4&c=entry&do=management&m=XXX

因为是app端的方法,所以会进入到site.php里面的doMobileHomecover()方法里面去。

下面是site.php里面的方法:

	public function __call($name, $arguments) {
		global $_W;
		$isWeb = stripos($name, 'doWeb') === 0;
		$isMobile = stripos($name, 'doMobile') === 0;
		if($isWeb || $isMobile) {
			$dir = IA_ROOT . '/addons/' . $this->modulename . '/';
			if($isWeb) {
				$dir .= 'web/';
				$controller = strtolower(substr($name, 5));
			}
			if($isMobile) {
				$dir .= 'app/';
				$controller = strtolower(substr($name, 8));
			}
			$file = $dir . 'index.php';
			if(file_exists($file)) {
				require $file;
				exit;
			}
		}
		trigger_error("访问的方法 {$name} 不存在.", E_USER_WARNING);
		return null;
	}
	public function doMobileHomecover(){
        global $_W;
		$dir = IA_ROOT . '/addons/' . $this->modulename . '/';
		$dir .= 'app/';
		$file = $dir . 'index.php';
		if(file_exists($file)) {
			require $file;
			exit;
		}		
		//print_r( $_W['openid']);
    }

一般来说,都是通过调用__call方法来进入某个链接,但这里需要通过封面链接来进入,所以需要写doMobileHomecover()这个方法。但doMobileHomecover()里面也只是为了进入到app\index.php。

2.在app\index.php里面设置默认的controller

<?php
define('IN_MOBILE', true);

global $_W,$_GPC;
wl_load()->model('member');
$this->check_in_weixin();//自己写的检查是否在微信中,不知道对不对

$controller = $_GPC['do'];
$action = $_GPC['ac'];

if (empty($controller) || empty($action)) {//绑定到封面
	$_GPC['do'] = $controller = 'scangenerate';
	$_GPC['ac'] = $action = 'scan';
}

$file = TG_APP . 'controller/'.$controller.'/'.$action.'.ctrl.php';

if (!file_exists($file)) {
	header("Location: index.php?i={$_W['uniacid']}&c=entry&do=scangenerate&ac=scan&m=vittor_homework_cabinet");
	exit;
}

require $file;

通过默认设置do与ac,假如二者有一个有一个为空时,就进入到你想要进入的controller里面去,即XXX.ctrl.php。

3.在XXX.ctrl.php里面默认设置op

$ops = array('这里面是可能的op');
$op = in_array($_GPC['op'], $ops) ? $_GPC['op'] : 'cover';

4.通过以上步骤,就能确定下来:

do:scangenerate

ac:scan

op:cover

而management只是为了最开始的导向







猜你喜欢

转载自blog.csdn.net/anlian523/article/details/80520772
今日推荐