在前2篇命名空間的部落格文章基礎上,我們來看一下,命名空間、公共空間與ThinkPHP5..0之間的關係:
首先我們找到index的控制器(controller),
\application\index\controller\Index.php,
修一下,修改過的Index.php:
<?php namespace app\index\controller; use think\Controller; class Index extends Controller { public function index(){ return $this->fetch(); } }
然後我們手動建立下面2個資料夾view和index,並建立用於控制index視圖的index.html,
\application\index\view\index\ index.html,
建立好的index.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title>iwanghang </head> <body> </body> </html>
\public\index.php,沒有做任何修改,我們運行一下,列印結果是iwanghang
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006-2016 http://www.php.cn/ All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.php.cn/ ) // +---------------------------------------------------------------------- // | Author: liu21st <liu21st@gmail.com> // +---------------------------------------------------------------------- // [ 应用入口文件 ] // 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 require __DIR__ . '/../thinkphp/start.php';
#