本文整理汇总了PHP中app\models\Tag::addTags方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::addTags方法的具体用法?PHP Tag::addTags怎么用?PHP Tag::addTags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Tag
的用法示例。
在下文中一共展示了Tag::addTags方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpdate
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$uploadFile = new UploadForm();
$uploadImg = new UploadForm();
if (Yii::$app->request->isPost) {
$uploadFile->file = UploadedFile::getInstance($uploadFile, 'file');
$uploadImg->img = UploadedFile::getInstance($uploadImg, 'img');
if ($uploadFile->file && $uploadFile->validate()) {
$uploadFile->file->saveAs('uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension);
} elseif ($uploadImg->img && $uploadImg->validate()) {
$uploadImg->img->saveAs('uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension);
} else {
print_r($uploadFile->getErrors());
}
}
if ($model->load(Yii::$app->request->post())) {
$model->text = Yii::$app->request->post('Items')['text'];
$model->tags = Yii::$app->request->post('Items')['tags'];
$model->title = Yii::$app->request->post('Items')['title'];
$model->cens = Yii::$app->request->post('Items')['cens'];
//$model->cat_id = Yii::$app->request->post('Items')['cat_id'];
if (Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()) {
$model->cat_id = Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()->id;
}
$model->audio_link = Yii::$app->request->post('Items')['audio_link'];
$model->in_work_prim = Yii::$app->request->post('Items')['in_work_prim'];
//$model->play_status = 1;
Tag::addTags($model->tags, $id);
//if(isset(Yii::$app->request->post('Items')['source_id']))$model->source_id = Yii::$app->request->post('Items')['source_id'];
//else $model->source_id = 2;
if (Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()) {
$model->source_id = Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()->id;
} else {
$model->source_id = 2;
}
if (isset($uploadFile->file)) {
$model->audio = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension;
}
if (isset($uploadImg->img)) {
$model->img = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension;
}
$model->save(false);
return $this->redirect(Url::toRoute('item/index'));
} else {
return $this->render('_form', ['model' => $model, 'uploadFile' => $uploadFile, 'uploadImg' => $uploadImg]);
}
}
示例2: actionRecordItem
/**
* Запись айтема
* @return string|void
*/
public function actionRecordItem()
{
if (Yii::$app->getRequest()->getQueryParam('user')) {
$user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
if (Yii::$app->getRequest()->getQueryParam('source') && Yii::$app->getRequest()->getQueryParam('tags') && Yii::$app->getRequest()->getQueryParam('cat') && Yii::$app->getRequest()->getQueryParam('txt') && Yii::$app->getRequest()->getQueryParam('title')) {
// return nl2br(Yii::$app->getRequest()->getQueryParam('txt'));
$act = new DiaryActs();
$act->model_id = 7;
$act->user_id = $user->id;
$act->mark = 1;
if ($act->save(false)) {
$item = new Items();
$item->text = Yii::$app->getRequest()->getQueryParam('txt');
$item->tags = Yii::$app->getRequest()->getQueryParam('tags');
$item->title = Yii::$app->getRequest()->getQueryParam('title');
$item->cens = Yii::$app->getRequest()->getQueryParam('cens');
// return var_dump($item);
if (Yii::$app->getRequest()->getQueryParam('old_data')) {
$item->old_data = Yii::$app->getRequest()->getQueryParam('old_data');
}
if (Categories::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('cat') . "'"))->one()) {
// return var_dump(Categories::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('cat')])->one()->id);
$item->cat_id = Categories::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('cat') . "'"))->one()->id;
} else {
return "Категория!";
}
$item->in_work_prim = '';
$item->play_status = 1;
if (Source::find()->where("title like '" . Yii::$app->getRequest()->getQueryParam('source') . "'")->one()) {
// return var_dump(Source::find()->where(['title' => Yii::$app->getRequest()->getQueryParam('source')])->one()->id);
$item->source_id = Source::find()->where("title like '" . trim(Yii::$app->getRequest()->getQueryParam('source') . "'"))->one()->id;
} else {
return var_dump($item);
}
$item->act_id = $act->id;
//return var_dump($item);
if ($item->save(false)) {
Tag::addTags($item->tags, $item->id);
}
}
return "<p>Сохранено!</p>";
}
return $this->renderPartial('add_item');
}
}