访问: www.test.com/admin
1============后台目录:admin (确保单一入口) --有入口文件index.php
<?php
require '../A/a.php'; //导入主程序
function mylog2($word){
$file = './mylog2.txt';
file_put_contents($file ,$word."
",FILE_APPEND);
}
$a = new a('admin');
$a->execute();
2===========主程序在A目录下a.php
<?php
define('DS','/');
define('A_PATH',str_replace('\','/',dirname(__FILE__)).DS);
class a {
public $app,$controller,$action,$class,$client;
public function __construct($clien){
$this->client = $clien;
}
public function execute(){
$this->app = $_GET['app'];
$this->controller = $_GET['controller'];
$this->action = $_GET['action'];
$this->args = $_GET; //接收所有,作为参数
$this->app_dir = A_PATH .'apps'.DS.$this->app.DS;
$file = $this->app_dir.'controller'.DS.$this->controller.'.php';
require($file);
$this->class = 'controller_'.$this->controller;
call_user_func_array( array($this->class,$this->action),array($this->args));
//http://www.test.com/admin/?app=system&controller=admin&action=login //自动调用登录方法 ,使用call_user_func_array()
//http://www.test.com/admin/?app=system&controller=index&action=index //自动调用后台index方法
//执行,指定类名 controller_index 指定方法index
}
}
3,4具体controller文件放置在主程序A目录下面-->apps下面---模块system-->controller
3========== admin.php 登录php
<?php
class controller_admin {
public function __construct($app){
//parent::__construct($app);
}
public function login(){
echo 'please login';
}
}
4=============index.php 显示登录后页面
<?php
class controller_index{
public function index(){
echo 'the index';
}
}
5===========自由调用各种模块下的各种方法(member模块)member.php
<?php
class controller_member{
public function reg(){
echo 'member register';
}
}
//http://www.test.com/admin/?app=member&controller=member&action=reg //自动调用后台index方法