• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP models\Option类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: sendEmail

 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([Option::get('admin_email') => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . Yii::$app->name)->send();
         }
     }
     return false;
 }
开发者ID:writesdown,项目名称:app-cms,代码行数:19,代码来源:PasswordResetRequestForm.php


示例17: testGroup

 public function testGroup(FunctionalTester $I)
 {
     $I->wantTo('ensure that setting works');
     $I->amOnPage(Url::to(['/setting/group', 'id' => 'general']));
     $I->see('General Settings', 'h1');
     $I->amGoingTo('update site title and tag line');
     $I->fillField('input[name="Option[sitetitle][option_value]"]', 'My New Website');
     $I->fillField('input[name="Option[tagline][option_value]"]', 'My New Website Tagline');
     $I->click('Save');
     $I->expectTo('see success message');
     $I->see('Settings successfully saved.');
     Option::up('sitetitle', 'WritesDown');
     Option::up('tagline', 'CMS Built with Yii Framework');
 }
开发者ID:ochiem,项目名称:app-cms,代码行数:14,代码来源:SettingCest.php


示例18: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $this->scenario = 'search';
     $query = Option::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'template_id' => $this->template_id, 'multiple' => $this->multiple, 'require' => $this->require, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
开发者ID:darkffh,项目名称:yii2-lowbase,代码行数:22,代码来源:OptionSearch.php


示例19: getAll

 /**
  * @param null $template_id
  * @return array
  */
 public static function getAll($template_id = null)
 {
     $options = [];
     if ($template_id) {
         $model = Option::find()->where(['template_id' => $template_id])->all();
     } else {
         $model = Option::find()->all();
     }
     if ($model) {
         foreach ($model as $m) {
             $options[$m->id] = $m->name;
         }
     }
     return $options;
 }
开发者ID:darkffh,项目名称:yii2-lowbase,代码行数:19,代码来源:Option.php


示例20: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             Yii::$app->authManager->assign(Yii::$app->authManager->getRole(Option::get('default_role')), $user->id);
             return $user;
         }
     }
     return null;
 }
开发者ID:tampaphp,项目名称:app-cms,代码行数:20,代码来源:SignupForm.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP models\Order类代码示例发布时间:2022-05-23
下一篇:
PHP models\LoginForm类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap