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


PHP Entry::resaveTags方法代码示例

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


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

示例1: actionCreate

 /**
  * @return void
  */
 public function actionCreate()
 {
     // create form
     $model = new Entry('create');
     // form is submitted
     if (isset($_POST['Entry'])) {
         $model->attributes = $_POST['Entry'];
         // save model & redirect to index
         if ($model->save()) {
             $model->resaveTags();
             // set flash
             Yii::app()->user->setFlash('success', 'The entry was created successfully.');
             // redirect to index
             $this->redirect(array('index'));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:humantech,项目名称:ppma,代码行数:21,代码来源:EntryController.php

示例2: actionCsv

    /**
     * @return void
     */
    public function actionCsv()
    {
        $model = new ImportCsvUploadForm();

        // upload form (first step) was submitted
        if (isset($_POST['ImportCsvUploadForm'])) {
            $model->attributes = $_POST['ImportCsvUploadForm'];

            // validate upload
            if ($model->validate()) {
                $models = array();

                // get file
                $file = CUploadedFile::getInstance($model, 'file');
                $fileContent = trim(file_get_contents($file->tempName));
                $fileLines = explode("\n", $fileContent);

                // relations between CSV and ImportCsvForm
                $csvToObject = array(
                    0 => 'name',
                    1 => 'url',
                    2 => 'comment',
                    3 => 'tags',
                    4 => 'username',
                    5 => 'password'
                );

                // traverse uploaded file per line
                foreach ($fileLines as $index => $line) {
                    // skip first line (header)
                    if ($index == 0) {
                        continue;
                    }

                    // parse line to array
                    $csv = str_getcsv($line);

                    if (count($csv) < 1) {
                        continue;
                    }

                    // create model
                    $tmpModel = new ImportCsvForm();

                    // set array values to model
                    foreach ($csvToObject as $position => $name) {
                        if (!isset($csv[$position])) {
                            break;
                        }

                        $tmpModel->$csvToObject[$position] = $csv[$position];
                    }

                    $models[] = $tmpModel;
                }
            }
        } elseif (isset($_POST['ImportCsvForm'])) { // import
            $models = array();
            $valid = true;

            foreach ($_POST['ImportCsvForm'] as $data) {
                $model = new ImportCsvForm();
                $model->attributes = $data;
                $valid = $model->validate();

                $models[] = $model;

                if (!$valid) {
                    Yii::app()->user->setFlash('hasError', true);
                }
            }

            if ($valid) {
                foreach ($models as $model) {
                    $entry = new Entry('create');
                    $entry->name = $model->name;
                    $entry->url = $model->url;
                    $entry->username = $model->username;
                    $entry->password = $model->password;
                    $entry->tagList = $model->tags;
                    $entry->comment = $model->comment;
                    $entry->save();
                    $entry->resaveTags();
                }

                Yii::app()->user->setFlash('success', 'Your CSV was successfully imported!');
                $this->redirect(array('/entry/index'));
            }
        }
        // render upload form
        if (!isset($models)) {
            $this->render('csv-upload', array('model' => $model, 'maxImport' => ceil(ini_get('max_input_vars') / 6)));
        } else { // render import form
            $this->render('csv-import', array('models' => $models));
        }
    }
开发者ID:hersoncruz,项目名称:ppma,代码行数:99,代码来源:ImportController.php


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