Exemplo n.º 1
0
 public function run()
 {
     $cacheKey = md5(__METHOD__);
     if (false === ($items = \Yii::$app->cache->get($cacheKey))) {
         $parents = ArrayHelper::map(PostMeta::find()->where(['parent' => null])->orWhere(['parent' => 0])->orderBy(['order' => SORT_ASC])->all(), 'id', 'name');
         foreach ($parents as $key => $value) {
             $nodes[$value] = PostMeta::find()->where(['parent' => $key])->asArray()->all();
         }
         $items = $nodes;
         //一天缓存
         \Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => [NamingHelper::getCommonTag(PostMeta::className())]]));
     }
     return $this->render('node', ['nodes' => $items]);
 }
Exemplo n.º 2
0
 public function getCategory()
 {
     return $this->hasOne(PostMeta::className(), ['id' => 'post_meta_id']);
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPostMeta()
 {
     return $this->hasMany(PostMeta::className(), ['post_id' => 'id']);
 }