Blogger Information
Blog 37
fans 2
comment 0
visits 26433
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
这是源码有高手能帮我调试下吗
世纪天城
Original
566 people have browsed it

问题

      为什么我入口文件放在项目根目录访问不到db类 但是能访问到控制器的方法

51655.png


以下是我的源代码  

实例

index.php入口文件

<?php
require_once 'Controllers/Routing.php';

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

Routing 路由文件

<?php
namespace cqmvc\Controllers\Routing;
class Routing{
    public function __construct(){
        // echo 1111;
        Routing::routing();
    }
    public static function routing(){
        // 路由
        $uri = $_SERVER['REQUEST_URI'];
        // echo $uri;
        $abc = explode('/',$uri);
        // echo '<pre>'. print_r($abc,true).'<pre>';
        $abb = array_slice($abc,3);
        // echo '<pre>'. print_r($abb,true).'<pre>';
        //创建变量
        list($module,$controller,$action) = $abb;
        // echo $module,' ',$controller,' ',$action;
        //将创建的变量放到一个关联数组中
        $add = compact('module','controller','action');
        // echo '<pre>'. print_r($add,true).'<pre>';
        //解析后续参数
        $arr = array_slice($abb,3);
        // echo '<pre>'. print_r($arr,true).'<pre>';
        //将参数打包到关联数组
        for($i=0;$i<count($arr);$i+=2){
            if(isset($arr[$i+1])){
                $bbt[$arr[$i]]=$arr[$i+1];
            }
        }
        include 'Controller.php';
    }
}
new Routing;

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

Controller 控制器文件

namespace cqmvc\Controllers\Controller;

use cqmvc\db\DB;
include '../db/DB.php';
class Controller{
    public static function index(){
        echo 111;
        // $abb = DB::select('lanmu');
        echo '<pre>';
        $abb =DB::selectAll('lanmu');
        print_r($abb);
    }
}
$abc = new Controller;
$abc->index();

运行实例 »

点击 "运行实例" 按钮查看在线实例



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post