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方法

  • 相关阅读:
    使用Vue初始化项目的时候,一直download template的解决方案
    移动端复选框和单选框选中样式不能正常显示
    PC端360浏览器如何打开手机模式
    我在项目中是这样配置Vue的
    怎么取消微信pc端“保持微信窗口在最前面”设置?
    5个 Vuex 插件,给你的下个VueJS项目
    Vue+Element前端导入导出Excel
    前端快来!最火的 Vue.js 开源项目出炉
    1月12日学习日志
    1月9日学习日志
  • 原文地址:https://www.cnblogs.com/bj-tony/p/5306827.html
Copyright © 2011-2022 走看看