當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Tags::setAttributes方法代碼示例

本文整理匯總了PHP中Tags::setAttributes方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tags::setAttributes方法的具體用法?PHP Tags::setAttributes怎麽用?PHP Tags::setAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Tags的用法示例。


在下文中一共展示了Tags::setAttributes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionCreate

 public function actionCreate()
 {
     $request = Yii::app()->request->getIsPostRequest();
     $ajaxRequest = Yii::app()->request->getIsAjaxRequest();
     if ($request) {
         $berita = new Berita();
         $kategori = new Kategori();
         $tags = new Tags();
         $image = new Image();
         $postBerita = !empty($_POST['Berita']) ? $_POST['Berita'] : "";
         $postKategori = !empty($_POST['Kategori']) ? $_POST['Kategori'] : "";
         $postTags = !empty($_POST['Tags']) ? $_POST['Tags'] : "";
         if ($kategori) {
             $kategori->setAttributes($postKategori);
         }
         if ($tags) {
             $tags->setAttributes($postTags);
         }
         if ($postBerita) {
             $berita->setAttributes($postBerita);
             $berita->setCreatetime($postBerita['tgl_create']);
             $berita->setUpdatetime($postBerita['tgl_update']);
         }
     }
     $jsonData = array();
     if ($ajaxRequest) {
         echo CJSON::encode($jsonData);
         Yii::app()->end();
     } else {
         $this->render("create", array());
     }
 }
開發者ID:hansenmakangiras,項目名稱:disperindag,代碼行數:32,代碼來源:BeritaController.php

示例2: testValidation

 public function testValidation()
 {
     $contact = $this->contacts('testAnyone');
     $tag = new Tags();
     $tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => 'test', 'taggedBy' => 'testuser'));
     $this->assertSaves($tag);
     // ensure that normalization was performed upon validation
     $this->assertEquals(Tags::normalizeTag('test'), $tag->tag);
     // ensure that tag must be unique
     $tag = new Tags();
     $tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => 'test', 'taggedBy' => 'testuser'));
     $tag->validate();
     $this->assertTrue($tag->hasErrors('tag'));
     // ensure that tag must be unique
     $tag = new Tags();
     $tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => '#test', 'taggedBy' => 'testuser'));
     $tag->validate();
     $this->assertTrue($tag->hasErrors('tag'));
     // ensure that tag must be unique
     $tag = new Tags();
     $tag->setAttributes(array('itemId' => $contact->id, 'type' => get_class($contact), 'itemName' => $contact->name, 'tag' => '#test,', 'taggedBy' => 'testuser'));
     $tag->validate();
     $this->assertTrue($tag->hasErrors('tag'));
 }
開發者ID:dsyman2,項目名稱:X2CRM,代碼行數:24,代碼來源:TagsTest.php

示例3: actionEdit

 public function actionEdit()
 {
     $this->layout = '//layouts/admin';
     $success = false;
     $id = $_REQUEST['id'];
     $model = NewsCategories::model()->findByPk($id);
     $this->pageTitle = is_object($model) ? $model->name : 'Новая категория';
     $this->breadcrumbs = array('Новости' => array('/admin/news'), 'Категории' => array('/admin/news/categories/list'), is_object($model) ? $model->name : 'Новая категория');
     if (isset($_POST['data']) && is_object($model)) {
         $tags = array();
         if (isset($_POST['data']['tags'])) {
             $tags = $_POST['data']['tags'];
             unset($_POST['data']['tags']);
         }
         $dataArray = $_POST['data'];
         $dataArray['is_active'] = isset($_POST['data']['is_active']) && $_POST['data']['is_active'] == 1 ? 1 : 0;
         $model->setAttributes($dataArray);
         if ($model->save()) {
             $success = true;
             if (isset($_FILES['anons_pic']) && $_FILES['anons_pic']['name'] || isset($_FILES['content_pic']) && $_FILES['content_pic']['name']) {
                 $uploaddir = 'images/upload/' . date("d.m.Y", time());
                 if (!is_dir($uploaddir)) {
                     mkdir($uploaddir);
                 }
                 if (isset($_FILES['anons_pic']) && $_FILES["anons_pic"]["name"]) {
                     if ($model->anons_pic) {
                         $anons_pic = Yii::app()->basePath . "/.." . $model->anons_pic;
                         if (is_file($anons_pic)) {
                             unlink($anons_pic);
                         }
                     }
                     $tmp_name = $_FILES["anons_pic"]["tmp_name"];
                     $name = $_FILES["anons_pic"]["name"];
                     if ($name) {
                         $uploadfile = $uploaddir . 'arca_' . $model->id . '_' . md5(basename($name) . time()) . "." . end(explode(".", $name));
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("anons_pic" => "/" . $uploadfile));
                             if (!$model->save()) {
                                 print_r($model->errors);
                                 die;
                             }
                         }
                     }
                 }
                 if (isset($_FILES['content_pic']) && $_FILES["content_pic"]["name"]) {
                     if ($model->content_pic) {
                         $content_pic = Yii::app()->basePath . "/.." . $model->content_pic;
                         if (is_file($content_pic)) {
                             unlink($content_pic);
                         }
                     }
                     $tmp_name = $_FILES["content_pic"]["tmp_name"];
                     $name = $_FILES["content_pic"]["name"];
                     if ($name) {
                         $uploadfile = $uploaddir . 'arcc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end(explode(".", $name));
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("content_pic" => "/" . $uploadfile));
                             $model->save();
                         }
                     }
                 }
             }
             if (is_array($tags) && count($tags)) {
                 $trs = TagsRelations::model()->findAllByAttributes(array("object_id" => $id, "model" => "news_category"));
                 if (is_array($trs) && count($trs)) {
                     foreach ($trs as $tr) {
                         $tr->delete();
                     }
                 }
                 foreach ($tags as $tag) {
                     $tagModel = Tags::model()->findByAttributes(array("name" => $tag));
                     if (!is_object($tagModel)) {
                         $tagModel = new Tags();
                         $tagModel->setAttributes(array("name" => $tag, "count" => 0));
                     }
                     $tagModel->count += 1;
                     $tagModel->save();
                     $tagsRelations = new TagsRelations();
                     $tagsRelations->setAttributes(array("tag_id" => $tagModel->id, "object_id" => $model->id, "model" => "news_category"));
                     $tagsRelations->save();
                 }
             }
         }
     }
     $this->render('edit', array('model' => $model, 'success' => $success, 'errors' => $model->errors));
 }
開發者ID:42point,項目名稱:Vinum,代碼行數:86,代碼來源:CategoriesController.php

示例4: actionEdit

 public function actionEdit()
 {
     $this->layout = '//layouts/admin';
     $success = false;
     $id = $_REQUEST['id'];
     $model = CatalogObjects::model()->findByPk($id);
     $this->pageTitle = is_object($model) ? $model->name : 'Новый товар';
     $this->breadcrumbs = array('Каталог' => array('/admin/catalog'), is_object($model) ? $model->name : 'Новый товар');
     if (isset($_POST['data']) && is_object($model)) {
         $tags = array();
         if (isset($_POST['data']['tags'])) {
             $tags = $_POST['data']['tags'];
             unset($_POST['data']['tags']);
         }
         $dataArray = $_POST['data'];
         $additionalDataArray = isset($dataArray['additional']) ? $dataArray['additional'] : array();
         unset($dataArray['additional']);
         $dataArray['is_active'] = isset($_POST['data']['is_active']) && $_POST['data']['is_active'] == 1 ? 1 : 0;
         $dataArray['on_main'] = isset($_POST['data']['on_main']) && $_POST['data']['on_main'] == 1 ? 1 : 0;
         $model->setAttributes($dataArray);
         if ($model->save()) {
             $success = true;
             if (isset($_FILES['anons_pic']) || isset($_FILES['content_pic'])) {
                 $uploaddir = 'images/upload/' . date("d.m.Y", time());
                 if (!is_dir($uploaddir)) {
                     mkdir($uploaddir);
                 }
                 if (isset($_FILES['anons_pic']) && $_FILES["anons_pic"]["name"]) {
                     if ($model->anons_pic) {
                         $anons_pic = Yii::app()->basePath . "/.." . $model->anons_pic;
                         if (is_file($anons_pic)) {
                             unlink($anons_pic);
                         }
                     }
                     $tmp_name = $_FILES["anons_pic"]["tmp_name"];
                     $name = $_FILES["anons_pic"]["name"];
                     if ($name) {
                         $ext = explode(".", $name);
                         $uploadfile = $uploaddir . '/na_' . $model->id . '_' . md5(basename($name) . time()) . "." . end($ext);
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("anons_pic" => "/" . $uploadfile));
                             $model->save();
                         }
                     }
                 }
                 if (isset($_FILES['content_pic']) && $_FILES["content_pic"]["name"]) {
                     if ($model->content_pic) {
                         $content_pic = Yii::app()->basePath . "/.." . $model->content_pic;
                         if (is_file($content_pic)) {
                             unlink($content_pic);
                         }
                     }
                     $tmp_name = $_FILES["content_pic"]["tmp_name"];
                     $name = $_FILES["content_pic"]["name"];
                     if ($name) {
                         $ext = explode(".", $name);
                         $uploadfile = $uploaddir . '/nc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end($ext);
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("content_pic" => "/" . $uploadfile));
                             $model->save();
                         }
                     }
                 }
                 if (isset($_FILES['extra_img']) && $_FILES["extra_img"]["name"]) {
                     if ($model->extra_img) {
                         $extra_img = Yii::app()->basePath . "/.." . $model->extra_img;
                         if (is_file($extra_img)) {
                             unlink($extra_img);
                         }
                     }
                     $tmp_name = $_FILES["extra_img"]["tmp_name"];
                     $name = $_FILES["extra_img"]["name"];
                     if ($name) {
                         $ext = explode(".", $name);
                         $uploadfile = $uploaddir . '/nc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end($ext);
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("extra_img" => "/" . $uploadfile));
                             $model->save();
                         }
                     }
                 }
             }
             if (is_array($tags) && count($tags)) {
                 $trs = TagsRelations::model()->findAllByAttributes(array("object_id" => $id, "model" => "catalog_object"));
                 if (is_array($trs) && count($trs)) {
                     foreach ($trs as $tr) {
                         $tr->delete();
                     }
                 }
                 foreach ($tags as $tag) {
                     $tagModel = Tags::model()->findByAttributes(array("name" => $tag));
                     if (!is_object($tagModel)) {
                         $tagModel = new Tags();
                         $tagModel->setAttributes(array("name" => $tag, "count" => 0));
                     }
                     $tagModel->count += 1;
                     $tagModel->save();
                     $tagsRelations = new TagsRelations();
                     $tagsRelations->setAttributes(array("tag_id" => $tagModel->id, "object_id" => $model->id, "model" => "catalog_object"));
                     $tagsRelations->save();
//.........這裏部分代碼省略.........
開發者ID:42point,項目名稱:Vinum,代碼行數:101,代碼來源:DefaultController.php


注:本文中的Tags::setAttributes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。