Rumah > php教程 > php手册 > [moka同学笔记]yii2.0 advanced高级版 安装配置 与 rbac (Ⅰ)

[moka同学笔记]yii2.0 advanced高级版 安装配置 与 rbac (Ⅰ)

WBOY
Lepaskan: 2016-08-10 08:49:37
asal
1362 orang telah melayarinya

1.下载地址:http://www.yiichina.com/download,下载 Yii2 的高级应用程序模板

2.配置与安装
在服务器www目录下yii2test  [下载下来更改advance为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> ],
Salin selepas log masuk
4.安装 AdminLTE 渲染后台  
  使用cmd 在yii2test目录下
<span style="color: #008080;">1</span> composer <span style="color: #0000ff;">require</span> dmstr/yii2-adminlte-asset "2.*"
Salin selepas log masuk

  

1.复制D:\phpStudy\WWW\yii2test\vendor\dmstr\yii2-adminlte-asset\example-views\yiisoft\yii2-app 下的 layouts和site 到   D:\phpStudy\WWW\yii2test\backend\views 中,覆盖重叠原来的文件。注意,在覆盖之前,请备份一下原来的文件

访问: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> ],
Salin selepas log masuk

② 下载 .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"
Salin selepas log masuk
 ②  在 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> ],
Salin selepas log masuk

  ③导入 rbac 表格

从数据库导入

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

  ④ 访问: http://yii2test/backend/web/admin/route

 

参考来源:http://www.yiichina.com/tutorial/876

以上~~

注:~

转载请注明出处。QQ1727728211

 

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan