代码拉取完成,页面将自动刷新
<?php
namespace app\controllers;
use app\models\Content;
use Yii;
use app\components\AppController as Controller;
use app\models\Feedback;
use app\models\Config;
use yii\data\ActiveDataProvider;
use app\models\Products;
use app\models\Ad;
use yii\web\NotFoundHttpException;
use app\models\Page;
use yii\helpers\Html;
class SiteController extends Controller
{
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
$products = Products::find()->where(['status'=>Products::STATUS_ENABLE])->orderBy('id desc')->limit(12)->all();
$aboutUs = Config::find()->where(['name'=>'about_us'])->one();
return $this->render('index', [
'aboutUs'=>$aboutUs,
'products' => $products,
]);
}
/**
* 修改语言
* @param string $language
* @return string
*/
public function actionLanguage($language)
{
if (isset(\app\models\Language::$lans[$language])){
yii::$app->language = $language;
return $this->redirect(\yii::$app->getUrlManager()->createUrl("index"));
}
}
/**
* Displays contact page.
*
* @return string
*/
public function actionContact()
{
$model = new Feedback();
/** @var Config $config */
$config = Config::getByName('contact_us_page_id');
if($config) {
$page = Page::find()->where(['id' => $config->value])->one();
} else {
$page = null;
}
if(!empty($page->keywords)){
$this->view->registerMetaTag(['name'=>'keywords', 'content'=>$page->keywords],'keywords');
}
if(!empty($page->description)){
$this->view->registerMetaTag(['name'=>'description', 'content'=>$page->description], 'description');
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if(isset(Yii::$app->params['adminEmail'])) {
$model->sendEmail(Yii::$app->params['adminEmail']);
}
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
'page' =>$page
]);
}
/**
* Displays about page.
* @return string
* @throws NotFoundHttpException
*/
public function actionAbout()
{
$config = Config::getByName('about_us_page_id');
if(empty($config)){
throw new NotFoundHttpException('页面不存在');
}
return $this->actionPage($config['value']);
}
/**
* Displays products page
*
* @return string
*/
public function actionSearch()
{
$keyword = Html::encode(strip_tags(Yii::$app->request->get('keyword')));
Content::$currentType = null;
$query = Content::find()
->andFilterWhere(['or',['like', 'title', $keyword],['like', 'description', $keyword]])
->andFilterWhere(['status'=>Content::STATUS_ENABLE]);
// echo $query->createCommand()->getRawSql();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=>['defaultOrder'=>['id'=>SORT_DESC]],
'pagination' => ['pageSize'=>Yii::$app->params['pageSize']]
]);
$this->view->params['keyword'] = $keyword;
return $this->render('search', [
'searchModel' => new Content(),
'dataProvider' => $dataProvider
]);
}
/**
* config 页面
* @param int $id
* @throws NotFoundHttpException
* @return string
*/
public function actionPage($id)
{
$page = Page::findOne($id);
if(empty($page)){
throw new NotFoundHttpException('页面不存在');
}
if(!empty($page->keywords)){
$this->view->registerMetaTag(['name'=>'keywords', 'content'=>$page->keywords],'keywords');
}
if(!empty($page->description)){
$this->view->registerMetaTag(['name'=>'description', 'content'=>$page->description], 'description');
}
return $this->render($page->template,[
'page'=>$page
]);
}
public function actionSearchChildren()
{
$this->layout = false;
return $this->render('search-children');
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。