<?php use yii\helpers\Html; /* @var $this \yii\web\View */ /* @var $content string */ $model = \common\models\User::findOne(['id' => Yii::$app->user->getId()]); $postCount = \common\models\Post::find()->where(['user_id' => $model['id']])->count(); $friendCount = \common\models\Relationship::find()->where(['user_id_1' => $model['id'], 'status' => 1])->count() + \common\models\Relationship::find()->where(['user_id_2' => $model['id'], 'status' => 1])->count(); $listNewRelNotify = \common\models\RelationshipNotification::find()->where(['receive_id' => Yii::$app->user->getId()])->orderBy('status')->limit(20)->asArray()->all(); $newRelNotifyCount = \common\models\RelationshipNotification::find()->where(['receive_id' => Yii::$app->user->getId(), 'status' => 0])->count(); $listNewMsgNotify = \common\models\Message::find()->where(['receiver_id' => Yii::$app->user->getId()])->orderBy('is_notified')->limit(20)->asArray()->all(); $newMsgNotifyCount = \common\models\Message::find()->where(['receiver_id' => Yii::$app->user->getId(), 'is_notified' => 0])->count(); ?> <header class="main-header"> <?php echo Html::a('<span class="logo-mini">APP</span><span class="logo-lg">' . Yii::$app->name . '</span>', Yii::$app->homeUrl, ['class' => 'logo']); ?> <nav class="navbar navbar-static-top" role="navigation"> <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"> <span class="sr-only">Toggle navigation</span> </a> <div class="navbar-custom-menu"> <ul class="nav navbar-nav"> <!-- Messages: style can be found in dropdown.less-->
public function saveCategory($categoryId) { //如果已经有分类且和新分类一致,则跳过 if ($this->category && $this->category->id == $categoryId) { return true; } $relationship = new Relationship(); //如果有分类,则查询久分类,然后分类的内容统计-1 if ($this->category && ($oldCategory = $relationship->find()->where(['content_id' => $this->id, 'meta_id' => $this->category->id])->one())) { Meta::updateAllCounters(['content_total' => -1], ['id' => $this->category->id]); $oldCategory->delete(); } $relationship->content_id = $this->id; $relationship->meta_id = $categoryId; if ($relationship->insert()) { //如果更新了分类,在新分类的内容数量+1,并且返回更新的条数 return Meta::updateAllCounters(['content_total' => 1], ['id' => $categoryId]); } return false; }