public static function getData($code, $other = [], $fromCache = true) { $cacheKey = self::CachePrefix . $code; $values = $fromCache ? LuLu::getCache($cacheKey) : false; if ($values === false) { $fragment = self::findOne(['code' => $code]); if ($fragment == null) { return []; } $query = $fragment->type === 1 ? Fragment1Data::find() : Fragment2Data::find(); $query->where(['fragment_id' => $fragment->id, 'status' => 1]); $query->orderBy('sort_num asc'); $values = $query->all(); LuLu::setCache($cacheKey, $values); } $offset = isset($other['offset']) ? $other['offset'] : 0; $limit = isset($other['limit']) ? $other['limit'] : count($values) - $offset; return array_slice($values, $offset, $limit, true); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Fragment1Data::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->fragment_id = LuLu::getGetValue('fid'); $query->andFilterWhere(['fragment_id' => $this->fragment_id]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // $query->andFilterWhere([ // 'id' => $this->id, // 'fragment_id' => $this->fragment_id, // 'sort_num' => $this->sort_num, // 'status' => $this->status, // ]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }