本文整理汇总了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));
}
示例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));
}
}