public function actionPlan() { $category_id = Category::findOne(['title' => '安全保障', 'status' => 1])->id; try { $infos = Article::find()->where(['category_id' => $category_id, 'status' => 1])->all(); } catch (ErrorException $e) { $infos = array(); } return $this->render('plan', compact("infos")); }
<?php use yii\helpers\Html; use yii\base\ErrorException; use common\models\cms\Category; use backend\models\Article; $directoryAsset = Yii::$app->assetManager->getPublishedUrl('@almasaeed/'); echo Html::cssFile('@web/myAssetsLib/css/style.css'); try { $parent_id = Category::findOne(['title' => '帮助中心', 'status' => 1])->id; $category = Category::find()->where(['parent_id' => $parent_id, 'status' => 1])->asArray()->all(); $left = array(); foreach ($category as $K => $V) { $has_parent_id = Category::find()->where(['parent_id' => $V['id'], 'status' => 1])->asArray()->all(); //var_dump($has_parent_id);exit; $left_second = array(); if ($has_parent_id) { foreach ($has_parent_id as $K1 => $V1) { $left_second[] = Category::find()->where(['id' => $V1['id'], 'status' => 1])->asArray()->all(); } } if (count($left_second) > 0) { $temp = Article::find()->where(['category_id' => $V['id'], 'status' => 1])->asArray()->all(); foreach ($left_second as $K_slice => $V_slice) { $temp = array_merge($temp, $left_second[$K_slice]); } $left[] = $temp; } else { $left[] = Article::find()->where(['category_id' => $V['id'], 'status' => 1])->asArray()->all(); } }
public function actionHelp() { $left = About::find()->asArray()->all(); try { $parent_id = Category::findOne(['title' => '帮助中心', 'status' => 1])->id; $infos = Article::find()->where(['category_id' => $parent_id, 'status' => 1]); $pages = new Pagination(['totalCount' => $infos->count(), 'pageSize' => '6']); $models = $infos->offset($pages->offset)->limit($pages->limit)->all(); } catch (ErrorException $e) { $infos = ''; $pages = ''; $models = ''; } return $this->render('help', compact("infos", "models", "pages", 'left')); }
public function actionHelp() { Utils::ensureOpenId(); $openId = Yii::$app->request->get('open_id'); if (($usermodel = UcenterMember::findOne(['openid' => $openId])) !== null) { Yii::$app->user->login($usermodel); } $parent_id = Category::findOne(['title' => '帮助中心', 'status' => 1])->id; $infos = Article::find()->where(['category_id' => $parent_id, 'status' => 1])->all(); return $this->view('help', compact('infos')); }