zoukankan      html  css  js  c++  java
  • A框架第一步,传递不同参数.主程序执行对应方法

    访问: 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方法

  • 相关阅读:
    bash 常用操作
    阿里云专有网络与弹性公网IP
    Excel 中 Index 和 Match 方法的使用
    分割excel sheet
    vba 工作案例-sheet间拷贝内容
    趣味题:重男轻女的村庄
    vba 工作案例1
    wordpress 导航相关的函数
    怎么样打印加密PDF文件
    excel 2013 图表制作
  • 原文地址:https://www.cnblogs.com/bj-tony/p/5306827.html
Copyright © 2011-2022 走看看