当前位置: 首页>>代码示例>>PHP>>正文


PHP Topic::save方法代码示例

本文整理汇总了PHP中Topic::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::save方法的具体用法?PHP Topic::save怎么用?PHP Topic::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Topic的用法示例。


在下文中一共展示了Topic::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeSave

 public function beforeSave($options = array())
 {
     //parent::beforeSave($options);
     //print_r($this->data);
     $loggedInUser = AuthComponent::user();
     $found = false;
     $userId = $loggedInUser['user_id'];
     $this->data['Post']['post_by'] = $userId;
     $this->data['Post']['post_date'] = (new DateTime())->format('Y-m-d');
     //format('Y-m-d H:i:s')
     if (!empty($this->data['Topic']['topic_subject'])) {
         $str = $this->data['Topic']['topic_subject'];
         $num = $this->data['Post']['post_cat'];
         $subject = new Topic();
         $found = $subject->find('first', array('conditions' => array('Topic.topic_subject LIKE' => $str, 'Topic.topic_cat =' => $num)));
         if (!$found) {
             $subject->create();
             //create topic
             $subject->save(array('topic_subject' => $this->data['Topic']['topic_subject'], 'topic_date' => (new DateTime())->format('Y-m-d'), 'topic_cat' => $this->data['Post']['post_cat'], 'topic_by' => $userId));
             //see also save associated model method cakephp
             $this->data['Post']['post_topic'] = $this->Topic->getLastInsertId();
             return true;
         }
         $this->data['Post']['post_topic'] = $found['Topic']['topic_id'];
         return true;
     }
     //nothing
     return true;
 }
开发者ID:s3116979,项目名称:BulletinBoard,代码行数:29,代码来源:Post.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (Auth::check()) {
         $data = Input::all();
         $rules = array('Title' => array('required', 'max:30'), 'Content' => array('required', 'max:500'), 'Category' => array('required'));
         $validator = Validator::make($data, $rules);
         if ($validator->fails()) {
             return Redirect::to('newTopic')->withErrors($validator);
         } else {
             $newTitle = Input::get('Title');
             $newContent = Input::get('Content');
             $newCategory = Input::get('Category');
             $user_id = Auth::user()->id;
             $topic = new Topic();
             $topic->title = $newTitle;
             $topic->content = $newContent;
             $topic->category_id = $newCategory;
             $topic->user_id = $user_id;
             $topic->save();
             return Redirect::to('forum');
         }
     } else {
         Redirect::to('login')->withErrors('You must be logged in to create a topic');
     }
 }
开发者ID:vinamilvinamil,项目名称:chatterr,代码行数:30,代码来源:TopicController.php

示例3: run

 public function run()
 {
     $table = $this->getTable();
     $title = 'Lorem ipsum dolor sit amet';
     $topic = new Topic(['title' => $title]);
     $topic->save();
 }
开发者ID:niclasleonbock,项目名称:eloquent-activatable,代码行数:7,代码来源:TopicTableSeeder.php

示例4: actionNew

 public function actionNew($groupId = null)
 {
     $data = array("type" => "new", "groupId" => $groupId);
     $data['groups'] = GroupUser::getGroups(GroupUser::find("userId", Rays::user()->id)->join("group")->order_desc("groupId")->all());
     if (Rays::isPost()) {
         $validation = new RValidation(array(array("field" => "title", "label" => "Title", "rules" => "trim|required"), array("field" => "group", "label" => "Group", "rules" => "trim|required|number"), array("field" => "post-content", "label" => "Content", "rules" => "trim|required")));
         if ($validation->run()) {
             $topic = new Topic();
             $topic->groupId = $_POST['group'];
             $topic->userId = Rays::user()->id;
             $topic->title = $_POST["title"];
             $topic->content = RHtml::encode($_POST['post-content']);
             $topic->createdTime = date('Y-m-d H:i:s');
             $topic->lastCommentTime = date('Y-m-d H:i:s');
             $topic->commentCount = 0;
             $topic->save();
             $this->redirectAction('post', 'view', $topic->id);
         } else {
             $data['newPostForm'] = $_POST;
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $this->layout = 'user';
     $this->addCss('/public/css/post.css');
     $this->setHeaderTitle("New post");
     $this->render("edit", $data, false);
 }
开发者ID:a4501150,项目名称:FDUGroup,代码行数:27,代码来源:PostController.php

示例5: addTopic

 function addTopic($title = 'none')
 {
     $toc = new Topic();
     $toc->tocTitle = $title;
     $toc->tocMax = 4;
     if ($toc->save()) {
         echo $toc->to_json();
     }
 }
开发者ID:htom78,项目名称:peersay,代码行数:9,代码来源:ormTest.php

示例6: create

 public function create()
 {
     foreach ($this->required as $required => $strlen) {
         if (!Input::has($required) || strlen(Input::get($required)) < $strlen) {
             return Response::make(['error' => 'You must introduce a ' . $required . ' with ' . $strlen . ' of length...'], 404);
         }
     }
     $new = new Topic();
     $new->fill(Input::only(['title', 'author', 'message']));
     $new->place = $this->place;
     $new->save();
     return Response::make(['success' => 'You just created a new topic!', 'topic' => $new->toArray()], 404);
 }
开发者ID:roffjump,项目名称:forum,代码行数:13,代码来源:TopicRestApiController.php

示例7: create

 public function create()
 {
     if (Request::isMethod('get')) {
         return View::make('forum::topic_create');
     }
     if (Request::isMethod('post')) {
         $new = new Topic();
         $new->fill(Input::only(['title', 'author', 'message']));
         $new->place = Input::has('api') ? 'api' : 'web';
         $new->save();
         return Redirect::to('/forum');
     }
 }
开发者ID:roffjump,项目名称:forum,代码行数:13,代码来源:TopicController.php

示例8: idsFromNames

 /**
  * Given a list of topic names, return the list of topic ids
  */
 public static function idsFromNames(array $names)
 {
     $ids = [];
     foreach ($names as $name) {
         $topic = static::whereName($name)->first();
         if (!$topic) {
             $topic = new Topic();
             $topic->name = $name;
             $topic->save();
         }
         $ids[] = $topic->id;
     }
     return $ids;
 }
开发者ID:binondord,项目名称:laravel-recipes,代码行数:17,代码来源:Topic.php

示例9: create_account

function create_account()
{
	global $CONF;
	$user = new RegUser();

	if (!preg_match("/^[".$CONF['nickname_chars']."]+$/i", $_POST['nickname_create_account']))
		return array('ok'=>false, 'error'=>'invalid nickname');

	if (trim($_POST['password_create_account'])=='')
		return array('ok'=>false, 'error'=>'no password');

	$user->setEmail($_POST['email_create_account']);
	$user->setNickname($_POST['nickname_create_account']);
	$user->setPassword($_POST['password_create_account']);
	if (isset($_POST['signature_create_account']))
		$user->setSignature($_POST['signature_create_account']);

	if (isset($_POST['camefrom_create_account']))
		$user->setCameFrom($_POST['camefrom_create_account']);

	$r = $user->save();
	if ($r=='ok')
	{
		$channel=new Channel();
		$channel->setId(1);
		$channel->forceFollow($user);
		$r = $user->sendEmail();
		if (!$r)
			return array('ok'=>false, 'error'=>'we could not send the e-mail.');
		else{
			$GLOBALS['user'] = $user;
			$rc = new RegUser();
			$rc->setNickname("RapidCoffee");
			$rc->load();
			$topic = new Topic();
			$topic->setChannel($channel);
			$topic->setUser($rc);
			$topic->setSubject("Dêem boas vindas ao usuário " . $user->getNickname() . "!");
			$msg = "Seja bem-vindo(a), <b>" . $user->getNickname() . "</b>. Criamos este tópico para que você possa se apresentar e conhecer um pouco dos usuários do site. Boa estadia =)<br /><br />Equipe Rapid Coffee.";
			$msg = str_replace('&nbsp;',' ',$msg);
			$topic->setMsg($msg);
			$topic->save();
			$topic->follow();
			return array('ok'=>true, 'error'=>'');
		}
	}
	return array('ok'=>false, 'error'=>$r);
}
开发者ID:rczeus,项目名称:Rapid-Coffee,代码行数:48,代码来源:create_account.php

示例10: store

 public static function store($group_id)
 {
     self::checkLoggedIn();
     $user = self::getUserLoggedIn();
     $params = $_POST;
     $topic = new Topic(array('title' => $params['title'], 'forum_group_id' => $group_id, 'creator' => $user->id));
     $errors = $topic->errors();
     $message;
     if (count($errors) == 0) {
         $topic->save();
         $message = array('message' => 'Aihe lisätty onnistuneesti');
     } else {
         $message = array('errors' => $errors);
     }
     Redirect::to('/groups/' . $group_id, $message);
 }
开发者ID:glvv,项目名称:Keskustelufoorumi,代码行数:16,代码来源:topic_controller.php

示例11: update_topic

function update_topic()
{
	global $user;
	global $CONF;

//	if (isset($_SESSION['topic_last_flood_time'])){
//
//		if ((time() - $_SESSION['topic_last_flood_time']) < $CONF['topic_time_to_wait_flood']){
//			$time_to_wait = $CONF['topic_time_to_wait_flood'] - (time() - $_SESSION['topic_last_flood_time']);
//			return array('ok'=>false, 'error'=>'flood '.$time_to_wait);
//		}
//
//	}

	$_SESSION['topic_last_flood_time']=time();

	$user = $_SESSION['user'];	

	$topic = new Topic();
	if (isset($_GET['topicid_update_topic'])){
		$topic->setId($_GET['topicid_update_topic']);
		$topic->load();
		if ( ($user->getId()!=$topic->getUser()->getId()) || ($user->isAnon()!=$topic->getUser()->isAnon()) )
			return array('ok'=>false, 'error'=>'you are not the owner');
	} else {
		return array('ok'=>false, 'error'=>'no id');
	}

	//$subject = strip_tags($_POST['subject']);
	//if (strlen(str_replace(' ', '', $subject)) < $CONF['min_msg_chars'])
	//	return array('ok'=>false, 'error'=>'Too short subject.');
	//$topic->setSubject($subject);

	$msg = unescape_ampersand($_POST['msg_update_topic']);
	if (strlen(str_replace(' ', '', strip_tags($msg))) < $CONF['min_msg_chars'])
		return array('ok'=>false, 'error'=>'Too short message.');

	$msg = strip_tags($msg, $CONF['permitted_tags_msg']);
	$topic->setMsg($msg);

	if ($topic->save()=='ok'){
		//$topic->follow();
		return array('ok'=>true, 'error'=>'');
	}
	else
		return array('ok'=>false, 'error'=>'problems with this topic');
}
开发者ID:rczeus,项目名称:Rapid-Coffee,代码行数:47,代码来源:update_topic.php

示例12: forumWrite

 public function forumWrite()
 {
     $json = Input::get('json');
     $data = json_decode($json);
     $writer = Student::where('auth', '=', $data->auth)->first();
     $sn = Topic::max('sn') + 1;
     $body = base64_decode($data->body);
     $topic = new Topic();
     $topic->sn = $sn;
     $topic->title = $data->title;
     $topic->stu_id = $writer->id;
     $topic->day = date("Y/m/d");
     $topic->body = $body;
     $topic->view = 0;
     $topic->save();
     return "suc";
 }
开发者ID:danncsc,项目名称:DaanX,代码行数:17,代码来源:ForumController.php

示例13: insertData

 public function insertData()
 {
     $gifts = json_decode(file_get_contents(app_path() . '/storage/gifts.txt'));
     $topics = json_decode(file_get_contents(app_path() . '/storage/topics.txt'));
     $gift_posters = json_decode(file_get_contents(app_path() . '/storage/gift_posters.txt'));
     $gift_photo_intros = json_decode(file_get_contents(app_path() . '/storage/gift_photo_intros.txt'));
     foreach ($topics as $topic) {
         $t = new Topic();
         $t->id = $topic->id;
         $t->title = $topic->title;
         $t->content = $topic->content;
         $t->topic_url = $topic->topic_url;
         if (!$t->save()) {
             return 'topic_false';
         }
     }
     foreach ($gifts as $gift) {
         $g = new Gift();
         $g->id = $gift->id;
         $g->topic_id = $gift->topic_id;
         $g->title = $gift->title;
         $g->price = $gift->price;
         $g->content = $gift->content;
         if (!$g->save()) {
             return 'gift_false';
         }
     }
     foreach ($gift_posters as $gift_poster) {
         $tp = new GiftPoster();
         $tp->gift_id = $gift_poster->gift_id;
         $tp->url = $gift_poster->url;
         if (!$tp->save()) {
             return 'gift_poster_false';
         }
     }
     foreach ($gift_photo_intros as $gift_photo_intro) {
         $gpi = new GiftPhotoIntro();
         $gpi->gift_id = $gift_photo_intro->gift_id;
         $gpi->url = $gift_photo_intro->url;
         if (!$gpi->save()) {
             return 'gift_photo_intro_false';
         }
     }
     return Response::json(array('errCode' => 0, 'message' => '插入成功'));
 }
开发者ID:Jv-Juven,项目名称:gift,代码行数:45,代码来源:MysqlController.php

示例14: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('name' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::to('topics/create')->withErrors($validator)->withInput(Input::except('password'));
     } else {
         // store
         $topic = new Topic();
         $topic->name = Input::get('name');
         $topic->description = Input::get('description');
         $topic->status = Input::get('status');
         //  $nerd->email      = Input::get('email');
         //  $nerd->nerd_level = Input::get('nerd_level');
         $topic->save();
         // redirect
         Session::flash('message', 'Successfully created topic!');
         return Redirect::to('topics');
     }
 }
开发者ID:kdrugov,项目名称:develwork,代码行数:26,代码来源:TopicController.php

示例15: create

 /**
  * @param Topic $topic
  * @return boolean
  */
 public function create($topic)
 {
     if ($this->validate()) {
         $user = Yii::$app->getUser()->getIdentity();
         $this->getPost()->topic_id = $topic->id;
         $this->getPost()->message = $this->message;
         $this->getPost()->save();
         $topic->updateCounters(['number_posts' => 1]);
         $topic->last_post_username = $user->username;
         $topic->last_post_created_at = time();
         $topic->last_post_id = $this->getPost()->id;
         $topic->last_post_user_id = $user->id;
         $topic->save();
         $forum = $topic->forum;
         $forum->updateCounters(['number_posts' => 1]);
         $forum->last_post_created_at = time();
         $forum->last_post_user_id = $this->getPost()->id;
         $forum->last_post_username = $user->username;
         $forum->save();
         return true;
     }
     return false;
 }
开发者ID:tecnologiaterabyte,项目名称:yii2-forum,代码行数:27,代码来源:PostForm.php


注:本文中的Topic::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。