1.去掉yii2模版默认的头部和脚部的两种方法:

  (1) 第一种

 $this->layout = false;
$this->render('index');

  (2) 第二种(partial意为局部的)

$this->renderPartial('index');

2.用AppAsset加载静态资源:

在对应前后台目录下的assets目录下的AppAsset.php文件中加入对应的css、js文件路径,然后再html页面进行注册,具体如下:

 <?php
use frontend\assets\AppAsset;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<?php $this->head() ?>
<?php $this->beginBody() ?>
<?php $this->endBody() ?>
<?php $this->endPage() ?>

以上缺一不可。

3.添加公共模版

在相应根目录下的views目录下的layouts文件夹下创建文件main.php(默认加载,如需其他名称需在控制器内render前添加$this->layout="layout"),放入公共模版后在中间添加占位

 <?php echo $content; ?>

4.非本地使用gii

在相应根目录下的config文件夹下的main-local文件下

 $config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['192.168.1.1'],
];

5.添加新模块

  (1)打开gii,进入Module Generator页面,按照页面的提示进行安装。

  (2)在相应根目录下的config文件夹下的main-local文件下

 if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
]; $config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
]; $config['module']['admin'] = [
'class' => 'app\modules\admin',
];
} return $config;

6.修改默认控制器为index(默认控制器为site)

在相应根目录下的config文件夹下的main文件下的return里,添加

 'defaultRoute' => 'index',

7.分页

参见:http://www.yiichina.com/tutorial/774

8.

最新文章

  1. Android 6.0 新特性
  2. ECMA 6 记入
  3. Timer,TimerTask通过程序计数器实现的定时任务
  4. FineReport使用总结
  5. LDA数学八卦笔记(一)Gamma函数
  6. python之路--操作系统介绍,进程的创建
  7. 索引使用,分析初探。(explain分析执行计划,以及强制使用force index)
  8. (Python基础)2 or 3?
  9. Sql日期时间格式转换[zhuan]
  10. Android常见问题及解决方案收集
  11. C语言注意点汇总
  12. 使用Django简单编写一个XSS平台
  13. Android 原生 Android ActionBar Tab (滑动)导航
  14. request.getParameter(&quot;name&quot;)获取参数为null和空字符串的区别
  15. 数制转换-栈的应用(C++实现)
  16. web工程jar包问题
  17. ObjectMapper处理从远程获取的Object对象 (http://bbs.csdn.net/topics/390337813?page=1)这个网址也有讲解
  18. 02 - Unit01:服务器返回数据的json处理+搭建项目环境
  19. C# 实现IP视频监控(摄像头)画面推送(简单的不能再简单的DEMO)
  20. JS 方法注入 attachEvent

热门文章

  1. Spring中的JdbcTemplate的使用
  2. tesseract的简单使用
  3. Flask 请求中间件、错误处理、标签、过滤器、CBV
  4. react 脚手架装后 运行eject报错 的 正确运行方式
  5. Natas18 Writeup(Session登录,暴力破解)
  6. SQLServer——MASTER..spt_values
  7. Eclipse新建项目介绍
  8. VIM不正常退出产生的swp文件
  9. leetcode 876. 链表的中间结点 签到
  10. 热点 | github近期热点项目汇总