在前2篇命名空間的博文基礎上,我們來看一下,命名空間、公用空間 與 ThinkPHP5..0之間的關係:
1、controller控制器
首先我們找到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視圖
然後我們手動建立下面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';
以上就是PHP開發(33)-ThinkPHP5.0(5)命名空間與TP5-PhpStorm的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!