ThinkPHP5.x + Apache配置及詳細(xì)使用

一 : ThinkPHP配置前準(zhǔn)備:

配置前需要安裝PHP5.4.0以上版本
ThinkPHP5.0完全開(kāi)發(fā)手冊(cè)

1 : 對(duì)于Mac系統(tǒng)
Mac上安裝配置Apache +Tomcat+JDK
2 : linux 或者 CentOS 等
php7詳細(xì)安裝教程(linux + nginx +PHP + mysql)
Linux 安裝和卸載 nginx操作

3 : 下面以本地電腦為例:
打開(kāi): http://localhost 顯示 it works ! 說(shuō)明Apache配置ok,
復(fù)制一個(gè)info.php文件到根目錄下,http://localhost/info.php顯示PHP相關(guān)信息說(shuō)明php環(huán)境ok.

在上面步驟3條件下,繼續(xù)往下

二 : ThinkPHP文件下載

下載方式一:
(1) : 官網(wǎng) http://www.thinkphp.cn/
注冊(cè)登錄官網(wǎng),直接下載:

圖片.png

(2) : 找到你的Apache的web根目錄,
比如我的是
/Library/WebServer/Documents/
將下載的文件直接解壓到該路徑下:

圖片.png

(3) : 打開(kāi)連接: http://localhost/public/
(注意: 如果你的項(xiàng)目不是在根路徑下,比如在創(chuàng)建項(xiàng)目/thinkPHPPro/下
那么路徑應(yīng)該是http://你的域名/thinkPHPPro/public)
顯示如下,說(shuō)明基礎(chǔ)環(huán)境ok:

圖片.png

如果不成功,給runtime文件設(shè)置一下權(quán)限:
chmod -R 777 /Library/WebServer/Documents/runtime

下載方式二 : 通過(guò)git 下載(4行語(yǔ)句) git安裝文檔

cd /Library/WebServer/Documents/
git init
git clone https://git.coding.net/liu21st/thinkphp5.git
git clone https://git.coding.net/liu21st/framework.git

(將thinkphp5移動(dòng)到framework文件夾下)

簡(jiǎn)單下載示例(可忽視):

-bash: php-version: command not found
localhost:niexiaobo niexiaobo$ cd /Users/niexiaobo/Downloads/php5 
localhost:php5 niexiaobo$ git init
Initialized empty Git repository in /Users/niexiaobo/Downloads/php5/.git/
localhost:php5 niexiaobo$ git clone https://git.coding.net/liu21st/thinkphp5.git
Cloning into 'thinkphp5'...
remote: Counting objects: 13519, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 13519 (delta 10), reused 0 (delta 0)
Receiving objects: 100% (13519/13519), 5.76 MiB | 3.20 MiB/s, done.
Resolving deltas: 100% (8588/8588), done.
localhost:php5 niexiaobo$ git clone https://git.coding.net/liu21st/framework.git
Cloning into 'framework'...
remote: Counting objects: 43528, done.
remote: Compressing objects: 100% (16100/16100), done.
remote: Total 43528 (delta 26953), reused 42770 (delta 26499)
Receiving objects: 100% (43528/43528), 10.67 MiB | 2.88 MiB/s, done.
Resolving deltas: 100% (26953/26953), done.
localhost:php5 niexiaobo$ 

三 : ThinkPHP文件目錄結(jié)構(gòu)

ThinkPHP 5相對(duì)于以往3的版本做了一些改變:

project 應(yīng)用部署目錄
├─application 應(yīng)用目錄(可設(shè)置)
│ ├─common 公共模塊目錄(可更改)
│ ├─index 模塊目錄(可更改)
│ │ ├─config.php 模塊配置文件
│ │ ├─common.php 模塊函數(shù)文件
│ │ ├─controller 控制器目錄
│ │ ├─model 模型目錄
│ │ ├─view 視圖目錄
│ │ └─ ... 更多類庫(kù)目錄
│ ├─command.php 命令行工具配置文件
│ ├─common.php 應(yīng)用公共(函數(shù))文件
│ ├─config.php 應(yīng)用(公共)配置文件
│ ├─database.php 數(shù)據(jù)庫(kù)配置文件
│ ├─tags.php 應(yīng)用行為擴(kuò)展定義文件
│ └─route.php 路由配置文件
├─extend 擴(kuò)展類庫(kù)目錄(可定義)
├─public WEB 部署目錄(對(duì)外訪問(wèn)目錄)
│ ├─static 靜態(tài)資源存放目錄(css,js,image)
│ ├─index.php 應(yīng)用入口文件
│ ├─router.php 快速測(cè)試文件
│ └─.htaccess 用于 apache 的重寫
├─runtime 應(yīng)用的運(yùn)行時(shí)目錄(可寫,可設(shè)置)
├─vendor 第三方類庫(kù)目錄(Composer)
├─thinkphp 框架系統(tǒng)目錄
│ ├─lang 語(yǔ)言包目錄
│ ├─library 框架核心類庫(kù)目錄
│ │ ├─think Think 類庫(kù)包目錄
│ │ └─traits 系統(tǒng) Traits 目錄
│ ├─tpl 系統(tǒng)模板目錄
│ ├─.htaccess 用于 apache 的重寫
│ ├─.travis.yml CI 定義文件
│ ├─base.php 基礎(chǔ)定義文件
│ ├─composer.json composer 定義文件
│ ├─console.php 控制臺(tái)入口文件
│ ├─convention.php 慣例配置文件
│ ├─helper.php 助手函數(shù)文件(可選)
│ ├─LICENSE.txt 授權(quán)說(shuō)明文件
│ ├─phpunit.xml 單元測(cè)試配置文件
│ ├─README.md README 文件
│ └─start.php 框架引導(dǎo)文件
├─build.php 自動(dòng)生成定義文件(參考)
├─composer.json composer 定義文件
├─LICENSE.txt 授權(quán)說(shuō)明文件
├─README.md README 文件
├─think 命令行入口文件

四 : ThinkPHP簡(jiǎn)單使用

(1) : 修改默認(rèn)頁(yè)面

上文中有介紹,打開(kāi)連接: http://localhost/public/顯示一段默認(rèn)頁(yè)面.
那么該頁(yè)面具體位置在哪呢?
對(duì)默認(rèn)項(xiàng)目的
application/index/controller/index.php
做一些簡(jiǎn)單的修改:

默認(rèn)代碼:

<?php
namespace app\index\controller;

 class Index
 {
     public function index()
     {
       return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一劍 - 為API開(kāi)發(fā)設(shè)計(jì)的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a  target="qiniu">七牛云</a> 獨(dú)家贊助發(fā)布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ad_bd568ce7058a1091"></think>';
    }
}

修改后:

<?php
namespace app\index\controller;

 class Index
 {
     public function index()
     {
        return  'Hello,World! this is default page !';
    }
}

保存后http://localhost/public鏈接顯示的就是 'Hello,World! this is default page !'這句話了.

(2) : 模板渲染
修改項(xiàng)目的application/index/controller/index.php文件:
主要修改有:引用Controller類 , 擴(kuò)展index類方法 , 添加方法hello.

修改后如下:

<?php
namespace app\index\controller;

use think\Controller;//引入Controller類
class Index extends Controller
{
   public function index()
    {
        return  'Hello,World! this is default page !';
    }
    public function hello()
    {
        return 'hello';
    }
    
}

打開(kāi)http://localhost/public/index.php/index/index/hello鏈接
顯示如下:

圖片.png

上述只是通過(guò)修改模板,無(wú)需創(chuàng)建相應(yīng)文件就可以返回.

(3) : 模板渲染, 并創(chuàng)建文件
還是修改項(xiàng)目的application/index/controller/index.php文件:
index方法,結(jié)果如下:

<?php
namespace app\index\controller;

use think\Controller;//引入Controller類
class Index extends Controller
{
   public function index($name='聶小波')
    {
        $this->assign('name',$name);
        return $this->fetch();
    }
    public function hello()
    {
        return 'hello';
    }
    
}

修改后index需要獲取變量的,此時(shí)打開(kāi)http://localhost/public鏈接會(huì)報(bào)錯(cuò)的,因?yàn)檫€沒(méi)有index.html文件.

進(jìn)入項(xiàng)目的application/index/下創(chuàng)建view文件夾,再進(jìn)入view下創(chuàng)建index文件夾進(jìn)入再創(chuàng)建index.html.(如下圖所示)

圖片.png

編輯index.html:

<html>
<head>
<title>hello {$name}</title>
</head>
<body>
    hello {$name}!
</body>
</html> 

打開(kāi)地址http://localhost/public/index.php/index/index顯示:

圖片.png

index.html展示時(shí)需要一個(gè)name變量值,而該值是通過(guò)index.php中模板方法傳遞過(guò)來(lái)的.

(5) : 通過(guò)參數(shù)param獲取內(nèi)容
修改上面index.php中的hello方法:

public function hello(Request $request)
    {
        echo 'hello :'.$request->param('name').'!';
        echo '你今年'.$request->param('age').'歲 !';
    }

打開(kāi)鏈接地址:
http://localhost/public/index.php/index/index/hello.html?name=bobo&age=18

參數(shù)有姓名和年齡,結(jié)果如圖:


圖片.png

(4) : 鏈接數(shù)據(jù)庫(kù)mysql
還是修改項(xiàng)目的application/index/controller/index.php文件:
準(zhǔn)備工作:
安裝mysql,創(chuàng)建數(shù)據(jù)庫(kù)testDB,創(chuàng)建表testTable,表里面添加幾條數(shù)據(jù),包含字段id, uname,等等

添加dbTest方法(域名localhost不行的話要用127.0.0.1),
use think\Db;//引入數(shù)據(jù)庫(kù)
結(jié)果如下:

<?php
namespace app\index\controller;

use think\Controller;//引入Controller類
use think\Db;//引入數(shù)據(jù)庫(kù)
class Index extends Controller
{
   public function index($name='聶小波')
    {
        $this->assign('name',$name);
        return $this->fetch();
    }
    public function hello()
    {
        return 'hello';
    }
   public function dbTest()
      {
        return Db::connect([
        'type'=>'mysql',
        'hostname'=>'127.0.0.1',
        'database'=>'testDB',
        'username'=>'root',
        'password'=>'root',
        ])
        ->table('testTable')
        ->where('id','2')
        ->value('uname');
     }
}

dbTest(): 查詢testTable表中id=2 的uname字段:
打開(kāi)鏈接http://localhost/public/index.php/index/index/dbtest
結(jié)果如下:

圖片.png

(6) : 統(tǒng)一配置數(shù)據(jù)庫(kù)mysql信息
在上面dbTest(): 中我們需要設(shè)置登錄信息, 下面開(kāi)始在公共文件統(tǒng)一配置:
進(jìn)入項(xiàng)目文件編輯: /application/database.php

return [
    // 數(shù)據(jù)庫(kù)類型
    'type'            => 'mysql',
    // 服務(wù)器地址
    'hostname'        => '127.0.0.1',
    // 數(shù)據(jù)庫(kù)名
    'database'        => 'testA',
    // 用戶名
    'username'        => 'root',
    // 密碼
    'password'        => 'root',
    // 端口
    'hostport'        => '3306',
    // 連接dsn
    'dsn'             => '',
    // 數(shù)據(jù)庫(kù)連接參數(shù)
    'params'          => [],
    // 數(shù)據(jù)庫(kù)編碼默認(rèn)采用utf8
    'charset'         => 'utf8',
    // 數(shù)據(jù)庫(kù)表前綴
.
.
.

還是修改項(xiàng)目的application/index/controller/index.php文件:

添加dbTest2方法(查詢testTable表下id=2的整條數(shù)據(jù)):

public function dbTest2()
    {
       $res = Db::table('testTable')->where('id',2)->find();
       dump(is_null($res)?'沒(méi)有查到':$res);
    }

打開(kāi)連接http://localhost/public/index.php/index/index/dbTest2
結(jié)果如下,返回成功,以后就不需要重復(fù)設(shè)置登錄信息了:

圖片.png

更多數(shù)據(jù)庫(kù)操作方法: ThinkPHP5.0完全開(kāi)發(fā)手冊(cè)

(https://www.cnblogs.com/samphp/p/8594291.html)
 //1、單條查詢
public function dbTest4()
{
$res = Db::table('pzq_article')
->field(['title'=>'標(biāo)題','id'=>'編號(hào)'])//可添加別名
->where('id','=',20)//如果是等號(hào),=可以省略
->find();//如果是主鍵查詢,可省略上面where,這行寫->find(20);
dump(is_null($res)?'沒(méi)有查到':$res);
}
//2、多條查旬
public function dbTest5()
{
$res = Db::table('pzq_article')
->field(['id','cat_id','title'])
->where([
['id','>',20],
['cat_id','=',2],
])//一個(gè)條件,直接用表達(dá)式->where('id','>',20)。多個(gè)條件用數(shù)組
->order('id desc')->limit(3)->select();

if(empty($res)){
return '沒(méi)有查到';
}else{
dump($res);
}

}

//3、數(shù)據(jù)添加
public function dbTest6()
{
$data = [
'name'=>'Sam2',
'age'=>'29',
'posttime'=>time()
];
$dataall=[
['name'=>'Sam3','age'=>'29','posttime'=>time()],
['name'=>'Sam4','age'=>'30','posttime'=>time()],
];
//(1)單條插入
//return Db::table('test')->data($data)->insert();
//(2)插入同時(shí)返回新增主鍵id
//return Db::table('test')->insertGetId($data);
//(3)插入多條數(shù)據(jù)
return Db::table('test')->data($dataall)->insertAll();
}
//4更新數(shù)據(jù)
public function dbTest7()
{
// return Db::table('test')
// ->where('id','=',4)
// ->update(['name'=>'SamC','age'=>'31']);
//如果where條件是主鍵,還可以如下使用
return Db::table('test')
->update(['name'=>'SamCheng','age'=>'30','id'=>4]);
}
//5刪除操作
public function dbTest8()
{
//return Db::table('test')->delete(6);
//或者
return Db::table('test')->where('id',5)->delete();
}
//mysql原生語(yǔ)句 查詢
public function dbTest9()
{
$sql = "select name,age from test where id>2";
dump(Db::query($sql));
}
//mysql 增、刪、改 用Db::execute($sql)
public function dbTest10()
{
//$sql = "update test set name='samC' where id=4";
//$sql = "insert test set name='Yan',age='30'";
$sql = "delete from test where id=4";
return Db::execute($sql);
}

五 : ThinkPHP路由設(shè)置

(7) : 路由: 隱藏真實(shí)路徑
修改項(xiàng)目路徑下 /application/route.php
修改前初始代碼:

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

return [
    '__pattern__' => [
        'name' => '\w+',
    ],
    '[hello]'     => [
        ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
        ':name' => ['index/hello', ['method' => 'post']],
    ],

];

添加一段代碼:

<?php

return [
    '__pattern__' => [
        'name' => '\w+',
    ],
    '[hello]'     => [
        ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
        ':name' => ['index/hello', ['method' => 'post']],
    ],

    '__alias__' =>  [
        'home'  =>  'index/index',
    ],
];

或者這樣寫:

    <?php
    use think\Route;
    Route::alias('home','index/index');

意思是真實(shí)路徑里的index/index都可以使用home來(lái)代替:
比如:步驟(6)中打開(kāi)連接http://localhost/public/index.php/index/index/dbTest2


打開(kāi)連接http://localhost/public/index.php/home/dbTest2
效果是一樣的.

更多路由設(shè)置參考 ThinkPHP5.1完全開(kāi)發(fā)手冊(cè)

(8) : 路由: 頁(yè)面跳轉(zhuǎn)
下面以登錄為例,登錄成功后跳轉(zhuǎn)到首頁(yè)index,失敗后跳轉(zhuǎn)錯(cuò)誤頁(yè)面

還是修改項(xiàng)目的application/index/controller/index.php文件:

添加login方法和check()方法:

// 顯示登錄頁(yè)面
    public function login(){
        return $this->fetch();
    }
    //提交登錄
    public function check(){
        //獲取參數(shù)
        $user=$_POST['username'];
        $pwd=$_POST['password'];

        // 判斷登陸成功失敗的邏輯
        if($user=='admin' && $pwd=='123'){
            //如果成功則跳到index/index頁(yè)面
            $this->success('登陸成功',url('/index/index'));
        }else{
            $this->error('登陸失敗');
        }
      }

下面路徑下創(chuàng)建login.html登錄驗(yàn)證頁(yè)面:
/application/index/view/index/login.html
代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陸</title>
</head>
<body>
    <!--{:url('check')}  :提交到本頁(yè)面的控制器下的check方法-->
    <form action="{:url('check')}" method="post">
        <p>
            賬號(hào):<input type="text" name="username" id="username">
        </p>
        <P>
            密碼:<input type="text" name="password" id="password">
        </P>
        <p>
            <input type="submit" value="提交">
            <input type="reset" value="重置">
        </p>
    </form>
</body>
</html>

打開(kāi)下面地址
http://localhost/public/index.php/index/index/login.html

圖片.png

輸入錯(cuò)誤的username,點(diǎn)擊提交按鈕:
登錄失敗, 跳轉(zhuǎn)錯(cuò)誤頁(yè)面(默認(rèn)3秒倒計(jì)時(shí)):


錯(cuò)誤頁(yè)面

輸入正確賬號(hào)密碼admin 和 123.
跳轉(zhuǎn)成功頁(yè)面(默認(rèn)3秒倒計(jì)時(shí)),然后回到index頁(yè)面:

圖片.png

(9) : 路由: 頁(yè)面重定向

打開(kāi)某個(gè)鏈接時(shí),直接跳轉(zhuǎn)到其他地址

還是修改項(xiàng)目的application/index/controller/index.php文件:
添加跳轉(zhuǎn)方法:

    // 頁(yè)面重定向
    public function jumpto(){
        $this->redirect('https://www.baidu.com');
    }

打開(kāi)鏈接:
http://localhost/public/index.php/index/index/jumpto
成功跳轉(zhuǎn)到百度頁(yè)面:

圖片.png

(10-A) : 模型的使用 : 查詢表
目的 : 通過(guò)創(chuàng)建使用Model來(lái)查詢表數(shù)據(jù)

詳細(xì)參考 : 模型定義文檔

1 : 首先數(shù)據(jù)庫(kù)有一張表chat.
2 : 在/application/index/下新建model文件夾,并創(chuàng)建一個(gè)Chat.php文件(根據(jù)表名, 駝峰命名,首字母大寫)
Chat.php :

<?php
namespace app\index\model;

use think\Model;
class Chat extends Model{
    // 設(shè)置當(dāng)前模型對(duì)應(yīng)的完整數(shù)據(jù)表名稱
    protected $table="chat";
}

?>

3 : 還是修改項(xiàng)目的application/index/controller/index.php文件:
添加跳轉(zhuǎn)方法:

//模型
    public function user()
    {
    // 實(shí)例化數(shù)據(jù)模型
    $user=new \app\index\model\Chat;
    //get(3): 查詢主鍵為3的數(shù)據(jù),并轉(zhuǎn)成array返回
    dump($user::get(3)->toArray());
    }

4 : 打開(kāi)連接:http://localhost/public/index.php/home/user
也即是http://localhost/public/index.php/index/index/user

圖片.png

(10-B) : 模型的理解
通過(guò)上述對(duì)模型的簡(jiǎn)單使用之后,接著對(duì)模型做一個(gè)簡(jiǎn)單是介紹:

1 這里的模型model到底是什么?

根據(jù)使用方法:

use think\Model;
class Chat extends Model

知道: 我們新建的Chat模型文件,其實(shí)是繼承了think\Model文件的功能和方法,說(shuō)明Chat模型在創(chuàng)建初始化結(jié)束后,就擁有了think下Model的功能.
修改上述控制器方法

//模型
    public function user()
    {
    // 實(shí)例化數(shù)據(jù)模型
    $user=new \app\index\model\Chat;
    //直接打印模型
    dump($user);
    }

打開(kāi)鏈接http://localhost/public/index.php/index/index/user
結(jié)果如下:

object(app\index\model\Chat)#10 (35) {
  ["table":protected] => string(10) "think_user"
  ["connection":protected] => array(0) {
  }
  ["parent":protected] => NULL
  ["query":protected] => NULL
  ["name":protected] => string(4) "Chat"
  ["class":protected] => string(20) "app\index\model\Chat"
  ["error":protected] => NULL
  ["validate":protected] => NULL
  ["pk":protected] => NULL
  ["field":protected] => array(0) {
  }
  ["except":protected] => array(0) {
  }
  ["disuse":protected] => array(0) {
  }
  ["readonly":protected] => array(0) {
  }
  ["visible":protected] => array(0) {
  }
  ["hidden":protected] => array(0) {
  }
  ["append":protected] => array(0) {
  }
  ["data":protected] => array(0) {
  }
  ["origin":protected] => array(0) {
  }
  ["relation":protected] => array(0) {
  }
  ["auto":protected] => array(0) {
  }
  ["insert":protected] => array(0) {
  }
  ["update":protected] => array(0) {
  }
  ["autoWriteTimestamp":protected] => bool(false)
  ["createTime":protected] => string(11) "create_time"
  ["updateTime":protected] => string(11) "update_time"
  ["dateFormat":protected] => string(11) "Y-m-d H:i:s"
  ["type":protected] => array(0) {
  }
  ["isUpdate":protected] => bool(false)
  ["force":protected] => bool(false)
  ["updateWhere":protected] => NULL
  ["failException":protected] => bool(false)
  ["useGlobalScope":protected] => bool(true)
  ["batchValidate":protected] => bool(false)
  ["resultSetType":protected] => string(5) "array"
  ["relationWrite":protected] => NULL
}

返回的一堆信息中:
第一條:
["table":protected] => string(10) "think_user" 意思是該模型設(shè)置的需要修改的表是think_user.
中間某條:
["append":protected] 意思是具有追加數(shù)據(jù)的功能
中間某條:
["data":protected] 專門存儲(chǔ)數(shù)據(jù)的
比如下面操作修改的就是這個(gè)data:

$user = new User;
$user->data([
    'name'  =>  'thinkphp',
    'email' =>  'thinkphp@qq.com'
]);

所以,模型文件能夠更好的幫我們處理一些數(shù)據(jù)庫(kù)相關(guān)的操作邏輯

(11) : 控制器 : 創(chuàng)建新的控制器
目前為止都是在項(xiàng)目的application/index/controller/index.php修改,這個(gè)默認(rèn)控制器文件index.php .

創(chuàng)建文件login.php:
application/index/controller/login.php
寫法和index.php一樣:

<?php
namespace app\index\controller;

class login 
{
    public function index()
    {
        return 'login !';
    }
    public function hello()
    {
        return 'hello';
    }
}

打開(kāi)地址:
http://localhost/public/index.php/index/login
http://localhost/public/index.php/index/login/hello

(11) : 后臺(tái)目錄文件
同默認(rèn)控制器,在 application/下創(chuàng)建admin文件,專門用來(lái)存放和管理后臺(tái)頁(yè)面代碼(開(kāi)發(fā)方式和上文基本一致):

控制器:
application/admin/controller/index.php
前端html入口(view下存放):
application/admin/view/index.html

圖片.png

前端html 的CSS,js,image等靜態(tài)文件存儲(chǔ)路徑:
/public/static/

圖片.png

前端html 的CSS,js,image靜態(tài)文件生效設(shè)置:
編輯/application/config.php:

 // 視圖輸出字符串內(nèi)容替換
    'view_replace_str'       => [
        '__PUBLIC__'=>'/public/static', //將__PUBLIC__指向public/static
        '__ROOT__' => '/',
    ],

引用/public/static下home/css文件:

<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/demo.css">

經(jīng)過(guò)上述配置后,訪問(wèn)http://localhost/public/index.php/admin/ 就可以進(jìn)入后臺(tái)管理界面.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,688評(píng)論 19 139
  • 理工寢室商店-微信小程序 疑問(wèn)小結(jié) 當(dāng)時(shí)在XAMMP下mysql目錄下的bin下 php -v 不起作用.到ph...
    這個(gè)超人不會(huì)飛阿閱讀 1,827評(píng)論 1 1
  • 作者:陳中舒時(shí)間:2017年5月11日 ThinkPHP 5.0的安裝 方式一:官網(wǎng)下載 官網(wǎng)地址:http://...
    忠叔閱讀 7,104評(píng)論 3 54
  • 我相信,任何一種感情都需要經(jīng)營(yíng),任何一種。 不管是友誼,還是愛(ài)情。都會(huì)需要一方的主動(dòng),或者雙方的配合。 兩人長(zhǎng)時(shí)間...
    bf7258edb119閱讀 918評(píng)論 0 6
  • 今年我26了。 寫下這個(gè)數(shù)字,一陣陌生感油然而生。 讀小學(xué)的時(shí)候總愛(ài)看鄰居姐姐那些花花綠綠的青春期少女雜志。印象最...
    好好活著的梅菜花閱讀 277評(píng)論 0 0

友情鏈接更多精彩內(nèi)容