本文整理汇总了PHP中app\models\Tag::getTagsIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::getTagsIn方法的具体用法?PHP Tag::getTagsIn怎么用?PHP Tag::getTagsIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Tag
的用法示例。
在下文中一共展示了Tag::getTagsIn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpdate
/**
* Updates an existing Post model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->updated_at = date("Y-m-d h:i:s");
$tag = new Tag();
$tmp = array();
$tags = array();
if (isset($_POST['Tag'])) {
$pieces = explode(",", Yii::$app->request->post()['Tag']['name']);
$dataProvider = Post_tags::getTags($id);
$count = $dataProvider->getModels();
for ($i = 0; $i < count($count); $i++) {
for ($j = 0; $j < count($pieces); $j++) {
if ($dataProvider->getModels()[$i]['name'] == $pieces[$j]) {
array_push($tmp, $pieces[$j]);
$pieces[$j] = "";
}
}
}
$dataProvider = Tag::getAllTags();
$count = $dataProvider->getModels();
for ($i = 0; $i < count($count); $i++) {
for ($j = 0; $j < count($pieces); $j++) {
if ($dataProvider->getModels()[$i]['name'] == $pieces[$j]) {
array_push($tmp, $pieces[$j]);
$pieces[$j] = "";
}
}
}
$ids = "'" . implode("','", $tmp) . "'";
$dataProvider2 = Tag::getTagsIn($ids);
for ($i = 0; $i < count($pieces); $i++) {
$tag = new Tag();
$tag->name = $pieces[$i];
$tag->save();
array_push($tags, $tag->tag_id);
}
for ($i = 0; $i < count($dataProvider2->getModels()); $i++) {
array_push($tags, $dataProvider2->getModels()[$i]['tag_id']);
}
}
$postTags = Post_tags::getPostTags($id);
for ($i = 0; $i < count($postTags->getModels()); $i++) {
for ($j = 0; $j < count($tags); $j++) {
if ($postTags->getModels()[$i]['tag_id'] == $tags[$j]) {
$tags[$j] = "";
}
}
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
for ($i = 0; $i < count($tags); $i++) {
$postTags = new Post_tags();
$postTags->tag_id = $tags[$i];
$postTags->post_id = $model->post_id;
$postTags->save();
}
return $this->redirect(['view', 'id' => $model->post_id]);
} else {
return $this->render('update', ['model' => $model, 'model' => $model, 'tag' => $tag]);
}
}