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


PHP Posts::save方法代码示例

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


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

示例1: edit

 public function edit($postID)
 {
     $post = new Posts();
     $post->load($postID);
     if (!$post->postID) {
         show_404();
     }
     $this->load->library('form_validation');
     $this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[3]|max_length[255]|xss_clean');
     $this->form_validation->set_rules('post', 'Text', 'trim|required|min_length[2]|max_length[255]|xss_clean');
     $this->form_validation->set_error_delimiters('<div class="alert alert-info" role="alert">', '</div>');
     if ($this->form_validation->run() == false) {
         $this->load->view('templates/template', ['main' => 'hello/add-edit', 'post' => $post]);
     } else {
         $post = new Posts();
         $post->postID = $this->uri->segment(3);
         $post->title = $this->input->post('title');
         $post->post = $this->input->post('post');
         $post->date_added = date('Y-m-d H:i:s');
         $post->userID = $this->session->userdata('userID');
         $post->active = 1;
         $post->save();
         $this->session->set_flashdata('message', 'Data updated');
         redirect('hello/view/' . $postID);
     }
 }
开发者ID:TraianAlex,项目名称:ci1,代码行数:26,代码来源:hello.php

示例2: addAction

 /**
  * Добавляет новую должность
  */
 public function addAction()
 {
     $result = array();
     $presentPost = \Posts::findFirst("title='" . $this->request->get("title") . "'");
     if ($presentPost != false) {
         $result['retcode'] = 1;
         $result['msgs'][] = "Посада із такою назвою вже існує!";
     } else {
         $namePost = new \Posts();
         $namePost->title = $this->request->get("title");
         if ($namePost->save() == false) {
             $result['retcode'] = 2;
             $result['msgs'][] = "Неможливо додати посаду \n";
             foreach ($namePost->getMessages() as $message) {
                 $result['msgs'][] = $message + "\n";
             }
         } else {
             $result['retcode'] = 0;
             $result['id'] = $namePost->id;
             $result['msgs'][] = "Нову посаду збережено";
         }
     }
     $this->view->disable();
     $this->response->setContentType('application/json', 'UTF-8');
     echo json_encode($result);
 }
开发者ID:sergeytkachenko,项目名称:angular-gulp-phalcon,代码行数:29,代码来源:PostsController.php

示例3: addAction

 public function addAction()
 {
     if ($this->_status['response']['status'] && $this->_checkToken()) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 301;
     }
     $post = ['entry' => true];
     if ($this->_status['response']['status'] && !$this->_getPost($post)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 201;
         $this->_status['response']['detail'] = $post['empty'];
     }
     $templateList = ['title' => null, 'tag' => null, 'category' => null, 'content' => null];
     $conditions = ['content'];
     if ($this->_status['response']['status'] && !$this->_mergeArray($this->_post['entry'], $templateList, $conditions)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 202;
         $this->_status['response']['detail'] = $conditions;
     }
     if (!$this->_status['response']['status']) {
         return $this->response->setJsonContent($this->_status);
     }
     $posts = new Posts();
     $posts->assign(['author' => $this->_id, 'title' => $this->_post['entry']['title'], 'content' => $this->_post['entry']['content']]);
     if (!$posts->save()) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 102;
         return $this->response->setJsonContent($this->_status);
     }
     if (!empty($this->_post['entry']['tag'])) {
         if (is_string($this->_post['entry']['tag'])) {
             $this->_post['entry']['tag'] = (array) $this->_post['entry']['tag'];
         }
         foreach ($this->_post['entry']['tag'] as $tag) {
             $tags = new Tags();
             $tags->assign(['posts_id' => $posts->id, 'tag' => $tag]);
             if (!$tags->save()) {
                 $this->_status['response']['status'] = false;
                 $this->_status['response']['code'] = 102;
                 return $this->response->setJsonContent($this->_status);
             }
         }
     }
     if (!empty($this->_post['entry']['category'])) {
         if (is_string($this->_post['entry']['category'])) {
             $this->_post['entry']['category'] = (array) $this->_post['entry']['category'];
         }
         foreach ($this->_post['entry']['category'] as $category) {
             $categories = new Categories();
             $categories->assign(['posts_id' => $posts->id, 'category' => $category]);
             if (!$categories->save()) {
                 $this->_status['response']['status'] = false;
                 $this->_status['response']['code'] = 102;
                 return $this->response->setJsonContent($this->_status);
             }
         }
     }
     return $this->response->setJsonContent($this->_status);
 }
开发者ID:gomasiyo,项目名称:cms,代码行数:59,代码来源:EntryController.php

示例4: addPost

 public function addPost($user_id, $post_content, $location, $url_arr, $album, $cats)
 {
     $model = new Posts();
     $model->post_content = $post_content;
     $model->post_comment_count = 0;
     $model->post_like_count = 0;
     $model->post_view_count = 0;
     $model->location = $location;
     $model->created_at = time();
     $model->status = 1;
     $model->updated_at = time();
     $model->user_id = $user_id;
     if (!$model->save(FALSE)) {
         return FALSE;
     }
     $cats = json_decode($cats, TRUE);
     foreach ($cats as $cat) {
         $cat_model = new CatPost();
         $cat_model->cat_id = $cat;
         $cat_model->post_id = $model->post_id;
         $cat_model->status = 1;
         $cat_model->created_at = time();
         $cat_model->updated_at = time();
         if (!$cat_model->save(FALSE)) {
             return FALSE;
         }
     }
     if (is_array($url_arr)) {
         foreach ($url_arr as $url) {
             $image = new Images();
             $image->post_id = $model->post_id;
             $image->created_at = time();
             $image->created_by = $user_id;
             $image->updated_at = time();
             $image->status = 1;
             $image->album_id = $album;
             $image->image_like_count = 0;
             $image->img_url = $url;
             if (!$image->save(FALSE)) {
                 return FALSE;
             }
         }
     } else {
         $image = new Images();
         $image->post_id = $model->post_id;
         $image->created_at = time();
         $image->created_by = $user_id;
         $image->updated_at = time();
         $image->status = 1;
         $image->album_id = $album;
         $image->image_like_count = 0;
         $image->img_url = $url_arr;
         if (!$image->save(FALSE)) {
             return FALSE;
         }
     }
     return $model->post_id;
 }
开发者ID:huynt57,项目名称:image_chooser,代码行数:58,代码来源:Posts.php

示例5: testStore

 public function testStore()
 {
     $post = new Posts();
     $post->id = 123;
     $post->title = 'GGC Test Post!';
     $post->temp_username = 'Joe';
     $post->message = 'This is a fake data blah blah blah';
     $post->topic_id = 1651;
     $post->save();
     Posts::findOrFail($post->id);
 }
开发者ID:Abenaman,项目名称:ggc-talk,代码行数:11,代码来源:PostTest.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $post = new Posts();
     $post->status = 1;
     // не одобрен
     $post->user_id = Auth::id();
     // юзер
     $post->title = Input::get('title');
     $post->content = Input::get('content');
     $post->lang = App::getLocale();
     $post->save();
     return Redirect::to('/managePosts');
 }
开发者ID:amadey18,项目名称:laravel_first_test,代码行数:18,代码来源:PostsController.php

示例7: createAction

 public function createAction()
 {
     $post = new Posts();
     $success = $post->save($this->request->getPost(), array('id_posta', 'poruka', 'created_at'));
     if ($success) {
         echo "Your message has been posted !";
     } else {
         echo "Sorry, the following problems were generated: ";
         foreach ($post->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
     $this->view->disable();
 }
开发者ID:bblazina,项目名称:twitterclone,代码行数:14,代码来源:PostsController.php

示例8: actionAdd

 public function actionAdd($id)
 {
     $text = Yii::app()->getRequest()->getPost('text');
     if ($text == 'Что нового') {
         $text = '';
     }
     if (empty($text) && !isset($_POST['files'])) {
         echo json_encode(array('status' => 'error', 'data' => 'Заполните все обязательные поля!'));
         exit;
     }
     $timestamp = time();
     $postObj = new Posts();
     $postObj->content = $text;
     $postObj->status = 1;
     $postObj->create_time = $timestamp;
     $postObj->author_id = Yii::app()->user->id;
     $postObj->owner_id = $id;
     $postObj->unique_hash = md5(Yii::app()->user->id . $id . $timestamp);
     $postObj->_owner = $id;
     // С чьей стены будем получать последние записи
     $postObj->_last_id = Yii::app()->getRequest()->getPost('lastEntryId');
     // id последней "видимой" записи
     $posts_files = PostsFiles::model();
     if ($postObj->save()) {
         if (isset($_POST['files'])) {
             $posts_files->addFiles($postObj->id);
         }
         if (Yii::app()->request->isAjaxRequest) {
             $posts = $postObj->lastAfterId();
             if (!empty($posts)) {
                 $res = '';
                 foreach ($posts as $key => $item) {
                     $files = $posts_files->findAll('posts_id = :posts_id', array(':posts_id' => $item['id']));
                     $res .= $this->renderPartial('//profile/profile/_wallItem', array('item' => $item, 'files' => $files, 'owner' => $id, 'display' => 'none'), true);
                 }
                 echo json_encode(array('status' => 'ok', 'data' => $res));
             } else {
                 echo json_encode(array('status' => 'error', 'data' => 'null'));
             }
         } else {
             throw new CException('Not Found', 404);
         }
     } else {
         if (Yii::app()->request->isAjaxRequest) {
             echo json_encode(array('status' => 'error', 'data' => 'Не могу соединиться с БД'));
         } else {
             throw new CException('Server error', 500);
         }
     }
 }
开发者ID:BGCX067,项目名称:facecom-svn-to-git,代码行数:50,代码来源:PostsController.php

示例9: actionShare

 public function actionShare()
 {
     $user_id = Yii::app()->user->id;
     $res = false;
     if (Yii::app()->request->isAjaxRequest && !empty($user_id)) {
         $item_id = Yii::app()->getRequest()->getPost('item_id');
         $sharedEntry = Posts::model()->findByPk($item_id);
         $newEntry = new Posts();
         $newEntryHash = md5($sharedEntry->author_type . $sharedEntry->author_id . $user_id . $sharedEntry->creation_date);
         if ($sharedEntry->owner_id == $user_id || $sharedEntry->author_id == $user_id || $sharedEntry->status != 1) {
             // если запись уже есть на стене или если запись заблочена то не добавляем
             echo json_encode(array('status' => 'error', 'data' => 'Ошибка при копировании записи'));
             exit;
         }
         $newEntry->parent_id = $sharedEntry->id;
         // поле parent_id устанавливаем отличное от нуля (id расшариваемого поста)
         $newEntry->post_type = 'userwall';
         // Все основные поля копируем как есть
         $newEntry->author_type = $sharedEntry->author_type;
         $newEntry->owner_type = 'user';
         $newEntry->content = $sharedEntry->content;
         $newEntry->multimedia = $sharedEntry->multimedia;
         $newEntry->status = $sharedEntry->status;
         $newEntry->creation_date = time();
         $newEntry->author_id = $sharedEntry->author_id;
         $newEntry->owner_id = $user_id;
         $newEntry->hash = $newEntryHash;
         // сохраняем новую и старую записи
         $transaction = $sharedEntry->dbConnection->beginTransaction();
         try {
             $newEntry->save();
             $sharedEntry->shares = intval($sharedEntry->shares) + 1;
             // увеличиваем счетчик share у копируемой записи
             $sharedEntry->save();
             $transaction->commit();
             $res = true;
         } catch (Exception $e) {
             $transaction->rollback();
             $res = false;
         }
         if ($res == true) {
             echo json_encode(array('status' => 'ok', 'data' => 'shared'));
         } else {
             echo json_encode(array('status' => 'error', 'data' => 'Ошибка подключения к БД'));
         }
     } else {
         throw new CException('Not Found', 404);
     }
 }
开发者ID:BGCX067,项目名称:facecom-svn-to-git,代码行数:49,代码来源:ShareController.php

示例10: store

 /**
  * Store a newly created post in storage.
  *
  * @return Response
  */
 public function store()
 {
     //$validator = Validator::make($data = Input::all(), Posts::$rules);
     //  if ($validator->fails())
     //  {
     //      return Redirect::back()->withErrors($validator)->withInput();
     //  }
     $post = new Posts();
     $post->topic_id = Input::get('topic_id');
     $post->temp_username = Input::get('temp_username');
     $post->title = 'test';
     $post->message = Input::get('message');
     $post->save();
     return Redirect::action('PostController@index');
 }
开发者ID:Abenaman,项目名称:ggc-talk,代码行数:20,代码来源:PostController.php

示例11: addPost

 public function addPost()
 {
     $memberID = Session::get('key');
     $post = new Posts();
     $post->title = Input::get('title');
     $post->content = Input::get('content');
     $post->visibility = Input::get('visibility');
     $post->memberID = $memberID;
     $post->date = date("d.m.Y", time());
     $post->save();
     $posts = DB::table('posts')->where('memberID', $memberID)->orderBy('created_at', 'desc')->get();
     $member = Members::find($memberID);
     $followings = DB::table('follow')->join('members', 'members.memberID', '=', 'follow.followMemberID')->where('follow.memberID', $memberID)->select('members.name', 'members.surname', 'members.memberID')->get();
     $followers = DB::table('follow')->join('members', 'members.memberID', '=', 'follow.memberID')->where('follow.followMemberID', $memberID)->select('members.name', 'members.surname', 'members.memberID')->get();
     return View::make('member/profile', array('share' => true, 'posts' => $posts, 'member' => $member, 'followers' => $followers, 'followings' => $followings));
 }
开发者ID:mitap45,项目名称:Daily,代码行数:16,代码来源:MemberController.php

示例12: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id = '')
 {
     if ($id) {
         $model = $this->loadModel($id);
     } else {
         $model = new Posts();
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Posts'])) {
         $model->attributes = $_POST['Posts'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:ph7pal,项目名称:mei,代码行数:21,代码来源:PostsController.php

示例13: create

 /**
  * Creates a new post
  */
 public function create($latitude, $longitude, $content, $user)
 {
     $post = new Posts();
     $post->users_id = $user->id;
     $post->latitude = $latitude;
     $post->longitude = $longitude;
     $post->content = $content;
     if ($post->save()) {
         return array(true, $post->toArray());
     } else {
         $errors = array();
         foreach ($post->getMessages() as $message) {
             $errors[] = (string) $message;
         }
         return array(false, $errors);
     }
 }
开发者ID:honerlaw,项目名称:archived-peekio,代码行数:20,代码来源:PostsComponent.php

示例14: createNewPost

 /**
  * Cria uma nova postagem
  * @param  date $post_date_create  data da criação do post
  * @param  date $post_date_posted  data que aparecerá no blog como postado
  * @param  date $post_date_changed data da ultima modificação da postagem
  * @param  int $post_author       id do autor da postagem
  * @param  int $post_editor       id do editor da postagem
  * @param  string $post_title        titulo do post
  * @param  string $post_content      conteudo da postagem
  * @param  id $post_status_id    status do post
  * @return int id da nova postagem caso sucesso ou zero caso false
  */
 public function createNewPost($post_date_create, $post_date_posted, $post_date_changed, $post_author, $post_editor, $post_title, $post_content, $post_status_id)
 {
     $post = new Posts();
     $post->post_blog = 1;
     $post->post_date_create = $post_date_create;
     $post->post_date_posted = $post_date_posted;
     $post->post_date_changed = $post_date_changed;
     $post->post_author = $post_author;
     $post->post_editor = $post_editor;
     $post->post_title = $post_title;
     $post->post_content = $post_content;
     $post->post_status_id = $post_status_id;
     if ($post->save()) {
         return $post->post_id;
     } else {
         return -1;
     }
 }
开发者ID:viniciusilveira,项目名称:pluton,代码行数:30,代码来源:Posts.php

示例15: run

 public function run()
 {
     $this->controller->pageTitle = "New Post";
     $this->controller->pageTitle = "New Post";
     if (Yii::app()->request->isAjaxRequest) {
         $img = Yii::app()->request->getParam('img');
         $content = CHtml::encode(Assist::removeXSS(Yii::app()->request->getParam('content')));
         $content = preg_replace('/\\n/mi', '<br/>', $content);
         $proxy = new Posts();
         $proxy->content = $content;
         $proxy->picture = $img;
         $proxy->userId = Yii::app()->user->id;
         $proxy->createTime = date('Y-m-d H:i:s', time());
         $proxy->save();
         echo CJSON::encode(array('code' => 200, 'message' => 'SUCCESS'));
     } else {
         $this->controller->render('newpost');
     }
 }
开发者ID:itliuchang,项目名称:test,代码行数:19,代码来源:NewPostAction.php


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