当前位置: 首页>>代码示例>>PHP>>正文


PHP models\Option类代码示例

本文整理汇总了PHP中common\models\Option的典型用法代码示例。如果您正苦于以下问题:PHP Option类的具体用法?PHP Option怎么用?PHP Option使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Option类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'update' page.
  *
  * @param integer $post_type post_type_id
  *
  * @throws \yii\web\ForbiddenHttpException
  * @throws \yii\web\NotFoundHttpException
  * @return mixed
  */
 public function actionCreate($post_type)
 {
     $model = new Post();
     $postType = $this->findPostType($post_type);
     $model->post_comment_status = Option::get('default_comment_status');
     if (!Yii::$app->user->can($postType->post_type_permission)) {
         throw new ForbiddenHttpException(Yii::t('writesdown', 'You are not allowed to perform this action.'));
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->post_type = $postType->id;
         $model->post_date = Yii::$app->formatter->asDatetime($model->post_date, 'php:Y-m-d H:i:s');
         if ($model->save()) {
             if ($termIds = Yii::$app->request->post('termIds')) {
                 foreach ($termIds as $termId) {
                     $termRelationship = new TermRelationship();
                     $termRelationship->setAttributes(['term_id' => $termId, 'post_id' => $model->id]);
                     if ($termRelationship->save() && ($term = $this->findTerm($termId))) {
                         $term->updateAttributes(['term_count' => $term->term_count++]);
                     }
                 }
             }
             if ($meta = Yii::$app->request->post('meta')) {
                 foreach ($meta as $meta_name => $meta_value) {
                     $model->setMeta($meta_name, $meta_value);
                 }
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('writesdown', '{post_type} successfully saved.', ['post_type' => $postType->post_type_sn]));
             return $this->redirect(['update', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model, 'postType' => $postType]);
 }
开发者ID:tampaphp,项目名称:app-cms,代码行数:42,代码来源:PostController.php

示例2: actionView

 /**
  * Displays a single User model.
  *
  * @param null $id
  * @param      $username
  *
  * @return mixed
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionView($id = null, $username = null)
 {
     $render = '/user/view';
     if ($id) {
         $model = $this->findModel($id);
     } else {
         if ($username) {
             $model = $this->findModelByUsername($username);
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     $query = $model->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]);
     $query->offset($pages->offset)->limit($pages->limit);
     $posts = $query->all();
     if ($posts) {
         if (is_file($this->view->theme->basePath . '/user/view-' . $model->username . '.php')) {
             $render = 'view-' . $model->username . '.php';
         }
         return $this->render($render, ['user' => $model, 'posts' => $posts, 'pages' => isset($pages) ? $pages : null]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:ochiem,项目名称:app-cms,代码行数:35,代码来源:UserController.php

示例3: actionIndex

 /**
  * @param int|null    $id        ID of post-type.
  * @param string|null $post_type Slug of post-type.
  *
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionIndex($id = null, $post_type = null)
 {
     $render = 'index';
     if ($id) {
         $postType = $this->findPostType($id);
     } else {
         if ($post_type) {
             $postType = $this->findPostTypeBySlug($post_type);
         } else {
             throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
         }
     }
     $query = $postType->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]);
     $query->offset($pages->offset)->limit($pages->limit);
     $posts = $query->all();
     if ($posts) {
         if (is_file($this->view->theme->basePath . '/post/index-' . $postType->post_type_slug . '.php')) {
             $render = 'index-' . $postType->post_type_slug . '.php';
         }
         return $this->render($render, ['postType' => $postType, 'posts' => $posts, 'pages' => $pages]);
     } else {
         throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
     }
 }
开发者ID:ochiem,项目名称:app-cms,代码行数:33,代码来源:PostController.php

示例4: getOptions

 /**
  * 获取网站配置数组
  * @return array
  */
 public static function getOptions()
 {
     if (self::$_options == null) {
         $options = \common\models\Option::find()->asArray()->all();
         self::$_options = yii\helpers\ArrayHelper::map($options, 'name', 'value');
     }
     return self::$_options;
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:12,代码来源:Option.php

示例5: saveForm

 public function saveForm()
 {
     if (!$this->validate()) {
         return false;
     }
     Option::updateOption(ArrayHelper::toArray($this));
     return true;
 }
开发者ID:Penton,项目名称:MoBlog,代码行数:8,代码来源:OptionGeneralForm.php

示例6: actionDelete

 /**
  * Deletes an existing Template model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     Option::deleteAll(['template_id' => $id]);
     $model->delete();
     Yii::$app->getSession()->setFlash('template-delete-success');
     return $this->redirect(['index']);
 }
开发者ID:darkffh,项目名称:yii2-lowbase,代码行数:14,代码来源:TemplateController.php

示例7: beforeValidate

 /**
  * @return bool
  * Динамическая валидация
  * @TODO  Углубленная валидация списков (с проверкой наличия базы), изображений
  */
 public function beforeValidate()
 {
     /** @var \common\models\Option $option */
     $option = Option::findOne($this->option_id);
     if ($option) {
         switch ($option->type) {
             case 1:
                 //число целое
             //число целое
             case 4:
                 //выключатель
             //выключатель
             case 8:
                 //список дочерних документов
             //список дочерних документов
             case 9:
                 //список потомков документа
             //список потомков документа
             case 10:
                 //список пользователей
                 $this->validators[] = Validator::createValidator('integer', $this, 'value');
                 break;
             case 2:
                 //число
                 $this->validators[] = Validator::createValidator('double', $this, 'value');
                 break;
             case 3:
                 //строка
             //строка
             case 5:
                 //текст
             //текст
             case 6:
                 //файл (выбор)
                 $this->validators[] = Validator::createValidator('string', $this, 'value');
                 break;
             case 7:
                 //изображение (загрузка)
                 $this->validators[] = Validator::createValidator('image', $this, 'file', ['minHeight' => 100, 'skipOnEmpty' => true]);
                 break;
             case 11:
                 //регулярное выражение
                 $pattern = $option->param ? $option->param : '\\w';
                 $this->validators[] = Validator::createValidator('match', $this, 'value', ['pattern' => $pattern]);
                 break;
         }
         if ($option->require) {
             if ($option->type == 7) {
                 if (!$this->value) {
                     $this->validators[] = Validator::createValidator('required', $this, 'file');
                 }
             } else {
                 $this->validators[] = Validator::createValidator('required', $this, 'value');
             }
         }
     }
     return true;
 }
开发者ID:darkffh,项目名称:yii2-lowbase,代码行数:63,代码来源:Field.php

示例8: actionIndex

 /**
  * @return string
  */
 public function actionIndex()
 {
     /* @var $lastPost \common\models\Post */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     $lastPost = Post::find()->where(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one();
     return $this->renderPartial('index', ['title' => Option::get('sitetitle'), 'description' => Option::get('tagline'), 'link' => Yii::$app->request->absoluteUrl, 'lastBuildDate' => new \DateTime($lastPost->post_date, new \DateTimeZone(Option::get('time_zone'))), 'postTypes' => PostType::find()->all(), 'language' => Yii::$app->language, 'generator' => 'http://www.writesdown.com']);
 }
开发者ID:wozhen,项目名称:yii2-cms-writedown,代码行数:12,代码来源:FeedController.php

示例9: setTheme

 /**
  * Set theme params
  *
  * @param Application $app the application currently running
  */
 protected function setTheme($app)
 {
     /* THEME CONFIG */
     $paramsPath = Yii::getAlias('@themes/') . Option::get('theme') . '/config/params.php';
     if (is_file($paramsPath)) {
         $params = (require $paramsPath);
         if ($backendParams = ArrayHelper::getValue($params, 'backend')) {
             $app->params = ArrayHelper::merge($app->params, $backendParams);
         }
     }
 }
开发者ID:writesdown,项目名称:app-cms,代码行数:16,代码来源:BackendBootstrap.php

示例10: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     $theme = Option::get('theme');
     $searchForm = Yii::getAlias('@themes/' . $theme . '/layouts/search-form.php');
     if (is_file($searchForm)) {
         $this->_searchForm = $searchForm;
     } else {
         $this->_searchForm = __DIR__ . '/views/search-form.php';
     }
     parent::init();
 }
开发者ID:writesdown,项目名称:app-cms,代码行数:14,代码来源:SearchWidget.php

示例11: setTheme

 /**
  * Set theme params
  *
  * @param Application $app the application currently running
  */
 protected function setTheme($app)
 {
     /* THEME CONFIG */
     $themeParamPath = Yii::getAlias('@themes/') . Option::get('theme') . '/config/params.php';
     if (is_file($themeParamPath)) {
         $themeParam = (require $themeParamPath);
         if (isset($themeParam['backend'])) {
             $app->params = ArrayHelper::merge($app->params, $themeParam['backend']);
         }
     }
 }
开发者ID:tampaphp,项目名称:app-cms,代码行数:16,代码来源:BackendBootstrap.php

示例12: actionIndex

 /**
  * Displaying feed.
  *
  * @return string
  */
 public function actionIndex()
 {
     /* @var $lastPost \common\models\Post */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     // Get first post and all posts
     $lastPost = Post::find()->where(['status' => Post::STATUS_PUBLISH])->andWhere(['<=', 'date', date('Y-m-d H:i:s')])->orderBy(['id' => SORT_DESC])->one();
     $posts = Post::find()->where(['status' => Post::STATUS_PUBLISH])->andWhere(['<=', 'date', date('Y-m-d H:i:s')])->limit(Option::get('posts_per_rss'))->orderBy(['id' => SORT_DESC])->all();
     return $this->renderPartial('index', ['title' => Option::get('sitetitle'), 'description' => Option::get('tagline'), 'link' => Yii::$app->request->absoluteUrl, 'lastBuildDate' => new \DateTime($lastPost->date, new \DateTimeZone(Option::get('time_zone'))), 'language' => Yii::$app->language, 'generator' => 'http://www.writesdown.com', 'posts' => $posts, 'rssUseExcerpt' => Option::get('rss_use_excerpt')]);
 }
开发者ID:writesdown,项目名称:app-cms,代码行数:16,代码来源:DefaultController.php

示例13: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = OptionModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'group', $this->group]);
     return $dataProvider;
 }
开发者ID:writesdown,项目名称:app-cms,代码行数:18,代码来源:Option.php

示例14: setTheme

 /**
  * Set theme params
  *
  * @param Application $app the application currently running
  */
 protected function setTheme($app)
 {
     $app->view->theme->basePath = '@themes/' . Option::get('theme');
     $app->view->theme->baseUrl = '@web/themes/' . Option::get('theme');
     $app->view->theme->pathMap = ['@app/views' => '@themes/' . Option::get('theme'), '@app/views/post' => '@themes/' . Option::get('theme') . '/post'];
     $paramsPath = Yii::getAlias('@themes/') . Option::get('theme') . '/config/params.php';
     if (is_file($paramsPath)) {
         $params = (require $paramsPath);
         if ($frontendParams = ArrayHelper::getValue($params, 'frontend')) {
             $app->params = ArrayHelper::merge($app->params, $frontendParams);
         }
     }
 }
开发者ID:writesdown,项目名称:app-cms,代码行数:18,代码来源:FrontendBootstrap.php

示例15: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = OptionModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'option_name', $this->option_name])->andFilterWhere(['like', 'option_value', $this->option_value])->andFilterWhere(['like', 'option_label', $this->option_label])->andFilterWhere(['like', 'option_group', $this->option_group]);
     return $dataProvider;
 }
开发者ID:tampaphp,项目名称:app-cms,代码行数:21,代码来源:Option.php


注:本文中的common\models\Option类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。