首頁  >  文章  >  php教程  >  [moka同學筆記]yii2.0 advanced進階版 安裝設定 與 rbac (Ⅰ)

[moka同學筆記]yii2.0 advanced進階版 安裝設定 與 rbac (Ⅰ)

WBOY
WBOY原創
2016-08-10 08:49:371337瀏覽

1.下載網址:http://www.yiichina.com/download,下載 Yii2 的高級應用程式範本

2.配置與安裝
在伺服器www目錄下yii2test  [下載下來更改ad​​vance為yii2test即可]
設定虛擬主機(略) 
 
   
安裝成功後,查看
前台  http://yii2test/frontend/web/index.php   
後台 http://yii2test/backend/web/index.php 
   安裝成功了。
3.配置連接資料庫
   在common/config/main-local.php
  
<span style="color: #008080;">1</span>   'db' =><span style="color: #000000;"> [
</span><span style="color: #008080;">2</span>     'class' => 'yii\db\Connection',
<span style="color: #008080;">3</span>     'dsn' => 'mysql:host=localhost;dbname=yii2test',
<span style="color: #008080;">4</span>     'username' => 'root',
<span style="color: #008080;">5</span>     'password' => 'root',
<span style="color: #008080;">6</span>     'charset' => 'utf8',
<span style="color: #008080;">7</span>     'tablePrefix'=>'yii2_',
<span style="color: #008080;">8</span> ],
4.安裝 AdminLTE 渲染後台  
  使用cmd 在yii2test目錄下
<span style="color: #008080;">1</span> composer <span style="color: #0000ff;">require</span> dmstr/yii2-adminlte-asset "2.*"

  

1.複製D:phpStudyWWWyii2testvendordmstryii2-adminlte-assetexample-viewsyiisoftyii2-app 下的 layouts和site 到   D:phpStudyWWWyii2testbackendviews 中,覆蓋重疊原來的檔案。注意,在覆蓋之前,請備份一下原來的檔案

訪問:http://yii2test/backend/web/index.php

2.url 美化

① 設定:backend/config/main.php 檔案的 compontents

<span style="color: #008080;">1</span> "urlManager" =><span style="color: #000000;"> [
</span><span style="color: #008080;">2</span>     <span style="color: #008000;">//</span><span style="color: #008000;">用于表明 urlManager 是否启用URL美化功能</span>
<span style="color: #008080;">3</span>     "enablePrettyUrl" => <span style="color: #0000ff;">true</span>,
<span style="color: #008080;">4</span>     <span style="color: #008000;">//</span><span style="color: #008000;"> 是否在URL中显示入口脚本</span>
<span style="color: #008080;">5</span>     "showScriptName" => <span style="color: #0000ff;">false</span>,
<span style="color: #008080;">6</span> ],

② 下載 .htaccess 文件,放在 backend/web 目錄下(這是為了隱藏 Index.php,apache必須要開啟rewrite模組)

 3.安裝 yii2-admin 整合 rbac
    ① 在cmd網站目錄下
<span style="color: #008080;">1</span> composer <span style="color: #0000ff;">require</span> mdmsoft/yii2-admin "2.x-dev"
 ②  在 backend/config/main.php 檔案中
<span style="color: #008080;"> 1</span> "modules" =><span style="color: #000000;"> [
</span><span style="color: #008080;"> 2</span>     "admin" =><span style="color: #000000;"> [
</span><span style="color: #008080;"> 3</span>         "class" => "mdm\admin\Module",
<span style="color: #008080;"> 4</span>     ],
<span style="color: #008080;"> 5</span> ],
<span style="color: #008080;"> 6</span> "aliases" =><span style="color: #000000;"> [
</span><span style="color: #008080;"> 7</span>     "@mdm/admin" => "@vendor/mdmsoft/yii2-admin",
<span style="color: #008080;"> 8</span> ],
<span style="color: #008080;"> 9</span> 'as access' =><span style="color: #000000;"> [
</span><span style="color: #008080;">10</span>     'class' => 'mdm\admin\components\AccessControl',
<span style="color: #008080;">11</span>     'allowActions' =><span style="color: #000000;"> [
</span><span style="color: #008080;">12</span>         <span style="color: #008000;">//</span><span style="color: #008000;">这里是允许访问的action
</span><span style="color: #008080;">13</span> <span style="color: #008000;">        //controller/action
</span><span style="color: #008080;">14</span> <span style="color: #008000;">    // * 表示允许所有,后期会介绍这个</span>
<span style="color: #008080;">15</span>         '*'
<span style="color: #008080;">16</span> <span style="color: #000000;">    ]
</span><span style="color: #008080;">17</span> ],
<span style="color: #008080;">18</span> 'components' =><span style="color: #000000;"> [
</span><span style="color: #008080;">19</span>     "authManager" =><span style="color: #000000;"> [
</span><span style="color: #008080;">20</span>         "class" => 'yii\rbac\DbManager',
<span style="color: #008080;">21</span>         "defaultRoles" => ["guest"],
<span style="color: #008080;">22</span>     ],
<span style="color: #008080;">23</span> ],

  ③導入 rbac 表格

從資料庫導入

vendor/yiisoft/yii2/rbac/migrations/schema-mysql.sql

  ④ 瀏覽: http://yii2test/backend/web/admin/route

 

參考來源:http://www.yiichina.com/tutorial/876

以上~~

註:~

轉載請註明出處。 QQ1727728211

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn