Table of Contents
下面这个方法是起到路由作用的,它是怎么完成这个流程的
Jun 20, 2016 pm 12:55 PM/** * 控制器调度 * */ private static function control(){ //二级域名 //var_dump($GLOBALS['setting_config']['enabled_subdomain']); if ($GLOBALS['setting_config']['enabled_subdomain'] == '1' && $_GET['act'] == 'index' && $_GET['op'] == 'index'){ $store_id = subdomain(); if ($store_id > 0) $_GET['act'] = 'show_store'; } $act_file = realpath(BASE_PATH.'/control/'.$_GET['act'].'.php'); $class_name = $_GET['act'].'Control'; //echo $act_file; if (!@include($act_file)){ if (C('debug')) { throw_exception("Base Error: access file isn't exists!"); } else { showMessage('抱歉!您访问的页面不存在','','html','error'); } } if (class_exists($class_name)){ $main = new $class_name(); $function = $_GET['op'].'Op'; if (method_exists($main,$function)){ $main->$function(); }elseif (method_exists($main,'indexOp')){ $main->indexOp(); }else { $error = "Base Error: function $function not in $class_name!"; throw_exception($error); } }else { $error = "Base Error: class $class_name isn't exists!"; throw_exception($error); } }
Copy after login
回复讨论(解决方案)
根据controler与action,判断要调用的类与方法
$act_file = realpath(BASE_PATH.'/control/'.$_GET['act'].'.php');$class_name = $_GET['act'].'Control';
Copy after login
然后判断如果类和方法存在则调用,就这样。
if (class_exists($class_name)){ $main = new $class_name(); $function = $_GET['op'].'Op'; if (method_exists($main,$function)){ $main->$function(); }elseif (method_exists($main,'indexOp')){ $main->indexOp(); }else { $error = "Base Error: function $function not in $class_name!"; throw_exception($error); } }
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

Build a React App With a Laravel Back End: Part 2, React

12 Best PHP Chat Scripts on CodeCanyon
