yii2中公共控制器向公共模板传数据
来源:互联网 发布:深圳市橙子网络 编辑:程序博客网 时间:2024/06/03 18:44
公共控制器
<?php
namespace frontend\controllers;use yii\web\Controller;
// use yii\base\Model;
use Yii;
/**
* user controller
*/
class CommonController extends Controller//继承原始控制器
{
public function init()//用init方法
{
parent::init();//继承
$user_id = Yii::$app->session->get('user_info')['id'];
//我的好友信息
$my_friend =\Yii::$app->db->createCommand("select username,u.id from user1 u join friend f on u.id=f.friend_id where f.user_id = $user_id and status = 1")->queryAll();
//我的好友中给我发的信息中未读的信息
$un_see =\Yii::$app->db->createCommand("select count(send_id) as num,send_id from user_info ui where ui.receive_id = $user_id and ui.status = 0 GROUP BY send_id")->queryAll();
foreach ($my_friend as $k => $v) {
foreach ($un_see as $k1 => $v1) {
if ($my_friend[$k]['id']==$un_see[$k1]['send_id']) {
$my_friend[$k1]['un_see_num'] = $un_see[$k1]['num'];
}
}
}
Yii::$app->view->params['my_friend'] = $my_friend;//设置参数用于公共模板调用
}
}
公共模板中这么调用
$this->params['my_friend']
0 0
- yii2中公共控制器向公共模板传数据
- YII2自定义公共方法
- thinkphp 独立分组公共控制器
- 最近公共祖先模板
- 公共模板和模板布局
- Yii2.0如何建立公共方法
- 公共数据库介绍~google公共数据
- 公共数据交换解决方案
- 公共数据列
- 获取weibo公共数据
- 最长公共子序列【模板】
- 【模板】最长公共子序列
- 最长公共子序列模板
- 最长公共子序列【模板】
- 最近公共祖先LCA【模板】
- 【模板】最长公共子序列
- noi2015模板-最近公共祖先
- 模板 - 最长公共子序列
- 小功能分享一键置顶
- .Net 内存溢出(System.OutOfMemoryException)的常见情况和处理方式总结
- python 解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe9 in position 9: ordinal not in rang
- 怎么才能把ppt转换成word文档
- Java反射与内省(Introspector)
- yii2中公共控制器向公共模板传数据
- 《Spring揭秘》第四章 读书笔记 —— Spring的IoC容器之BeanFactory
- retrofit2+okhttp3图片上传及进度监听
- 常用正则表达式大全
- VMWARE虚拟机三种网络模式(BRIDGED,NAT,HOST-ONLY)区别详解
- STL---集合的运算
- codevs 1079 回家(最短路)
- Android平台AES对称加密踩过的坑
- vpn入门文章