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