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


PHP Articles::validate方法代码示例

本文整理汇总了PHP中Articles::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Articles::validate方法的具体用法?PHP Articles::validate怎么用?PHP Articles::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Articles的用法示例。


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

示例1: actionCreate

 public function actionCreate()
 {
     $model = new Articles();
     if (isset($_POST['Articles'])) {
         $model->attributes = $_POST['Articles'];
         $model->author_id = Yii::app()->user->id;
         if ($model->validate()) {
             $model->save();
             Yii::app()->user->setFlash('success', Yii::t('main', 'Успішно додано!'));
             $this->redirect('index');
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:Vladimirtishenko,项目名称:val.ua,代码行数:14,代码来源:CabinetController.php

示例2: actionNew_article

 /**
  * Добавление статьи пользователем
  */
 public function actionNew_article()
 {
     if (Yii::app()->request->isAjaxRequest) {
         if (isset($_POST['idMenu'])) {
             $category1 = array('' => 'Без категории');
             $category2 = Categorys::getAllCategories($_POST['idMenu']);
             $category = $category1 + $category2;
             $filteredCategory = array();
             $i = 0;
             foreach ($category as $key => $val) {
                 $filteredCategory[$i]['id'] = $key;
                 $filteredCategory[$i]['title'] = $val;
                 $i++;
             }
             echo CJSON::encode(array('categorys' => $filteredCategory));
             exit;
         }
     }
     // Проверки на доступ к странице
     if (Yii::app()->user->isGuest) {
         $this->redirect(Yii::app()->homeUrl);
     }
     if (isset($_POST['cancel'])) {
         $this->redirect(Yii::app()->homeUrl);
     }
     $model = new Articles('create');
     // Нажата кнопка "Редактировать" или "Добавить"
     if (isset($_POST['Articles'])) {
         $oldFile = null;
         $oldFile = $model->photo;
         // Генерим имя фото
         if ('' != $_FILES['Articles']['name']['image']) {
             $fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Articles']['name']['image']);
             $_POST['Articles']['photo'] = $fileName;
             $oldFile = $model->photo;
         }
         $model->attributes = $_POST['Articles'];
         $model->idUser = Yii::app()->user->id;
         if ($model->validate()) {
             if ($model->save()) {
                 if ($fileName) {
                     AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile);
                 }
                 if (1 == $model->public && 1 == $model->moderationAppruv) {
                     $this->redirect($this->createAbsoluteUrl('articles/view_article', array('idArticle' => $model->idArticle, 'idMenu' => $model->idMenu)));
                 }
                 $this->redirect($this->createAbsoluteUrl('base/index', array('referrer' => 'new_article')));
             }
         }
     }
     $menus = Mainmenu::model()->getDropDownMenu();
     $idMenu = !empty($model->idMenu) ? $model->idMenu : key($menus);
     $category1 = array('' => 'Без категории');
     $category2 = Categorys::getAllCategories($idMenu);
     $category = $category1 + $category2;
     $this->render('new_article', array('model' => $model, 'menus' => $menus, 'category' => $category));
 }
开发者ID:vitalya-xxx,项目名称:vitacod.ru,代码行数:60,代码来源:ArticlesController.php

示例3: actionSave_article

 public function actionSave_article()
 {
     $idArticle = null;
     // Проверки на доступ к странице
     if (Yii::app()->user->isGuest) {
         $this->redirect($this->createAbsoluteUrl('default/index'));
     }
     if (isset($_POST['cancel'])) {
         $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET));
     }
     if (isset($_POST['delete'])) {
         $this->actionDelete_article();
         $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET));
     }
     // Автокомплитер тегов
     if (isset($_GET['q'])) {
         $lastTag = end(explode(",", $_GET['q']));
         $criteria = new CDbCriteria();
         $criteria->condition = 'textTag LIKE :tag';
         $criteria->params = array(':tag' => '%' . trim(htmlspecialchars($lastTag)) . '%');
         if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
             $criteria->limit = $_GET['limit'];
         }
         $tags = Tags::model()->findAll($criteria);
         if ($tags) {
             $resStr = '';
             foreach ($tags as $tag) {
                 $resStr .= $tag->textTag . "\n";
             }
             echo $resStr;
         }
         exit;
     }
     // Редактирование или добавление новой
     if (isset($_GET['idArticle'])) {
         $idArticle = $_GET['idArticle'];
         $model = Articles::model()->findByPk($_GET['idArticle']);
         $model['tagArray'] = AuxiliaryFunctions::getTagsList($model->tagstoarticles, false);
     } else {
         $model = new Articles('create');
     }
     // Нажата кнопка "Редактировать" или "Добавить"
     if (isset($_POST['Articles'])) {
         $oldFile = null;
         $oldFile = $model->photo;
         $fileName = null;
         // Генерим имя фото
         if ('' != $_FILES['Articles']['name']['image']) {
             $fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Articles']['name']['image']);
             $_POST['Articles']['photo'] = $fileName;
             $oldFile = $model->photo;
         }
         $model->attributes = $_POST['Articles'];
         if (empty($model->idUser)) {
             $model->idUser = Users::getIdUserForAdmin();
         }
         if ($model->validate()) {
             if ($model->save()) {
                 $idArticle = $model->idArticle;
                 if ($fileName) {
                     AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile);
                 }
                 // Теги для статьи
                 if (isset($_POST['textTag'])) {
                     $tagsArray = explode(",", $_POST['textTag']);
                     $idArray = array();
                     foreach ($tagsArray as $item) {
                         $tagId = null;
                         if (!empty($item)) {
                             $item = trim(htmlspecialchars($item));
                         } else {
                             continue;
                         }
                         $tagResult = Tags::model()->findByAttributes(array('textTag' => $item));
                         if (null === $tagResult) {
                             $newTag = new Tags();
                             $newTag->textTag = $item;
                             if ($newTag->save()) {
                                 $tagId = $newTag->idTag;
                             }
                         } else {
                             $tagId = $tagResult->idTag;
                         }
                         $idArray[] = $tagId;
                     }
                     if ($idArray) {
                         foreach ($idArray as $item) {
                             $item = (int) $item;
                             $idArticle = (int) $idArticle;
                             if (!TagsToArticles::model()->exists('idArticle = :idArticle AND idTag = :idTag', array(':idArticle' => $idArticle, ':idTag' => $item))) {
                                 $newTags2Art = new TagsToArticles();
                                 $newTags2Art->idArticle = $idArticle;
                                 $newTags2Art->idTag = (int) $item;
                                 $newTags2Art->save();
                             }
                         }
                     }
                 }
                 $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET));
             }
//.........这里部分代码省略.........
开发者ID:vitalya-xxx,项目名称:vitacod.ru,代码行数:101,代码来源:DefaultController.php


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