本文整理汇总了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());
}
}
示例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'));
}
示例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));
}
示例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();
//.........这里部分代码省略.........