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


PHP Post::validate方法代碼示例

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


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

示例1: actionCreate

 public function actionCreate()
 {
     //$data = (array)json_decode( file_get_contents('php://input') );
     //echo (var_dump($data));
     $model = new Post();
     $model->setAttributes($this->getJsonInput());
     //$model->setAttributes($data);
     if (!$model->validate()) {
         $this->sendResponse(400, CHtml::errorSummary($model));
     } else {
         if (!$model->save(false)) {
             throw new CException('Cannot create a record');
         }
     }
     $model->refresh();
     echo CJSON::encode($model);
     /*
     		if(isset($_GET['id']))
                 $id=$_GET['id'];
     		$posts = Post::model()->findAllByAttributes(array("author"=>1));
     		foreach($posts as $p) {
     			$author = User::model()->findByPk($p['author']);
     			$p['author'] = $author['name'];
     		}
     		echo CJSON::encode($posts);*/
 }
開發者ID:Eisenheim94,項目名稱:blog,代碼行數:26,代碼來源:ApiController.php

示例2: doValidate

 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUser !== null) {
             if (!$this->aUser->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
             }
         }
         if ($this->aPost !== null) {
             if (!$this->aPost->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aPost->getValidationFailures());
             }
         }
         if (($retval = CommentPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
開發者ID:alexspark21,項目名稱:symfony_bisM,代碼行數:37,代碼來源:BaseComment.php

示例3: postit

 public function postit()
 {
     $post = new Post(array("from_user" => $this->user->id, "title" => RequestMethods::post('title'), "content" => RequestMethods::post('content'), "category" => RequestMethods::post('category')));
     if ($post->validate()) {
         $post->save();
         return "success";
     } else {
         return "validation not good";
     }
 }
開發者ID:shreyanshgoel,項目名稱:blog,代碼行數:10,代碼來源:users.php

示例4: post_create

 public function post_create()
 {
     $validation = Post::validate(Input::all());
     if ($validation->fails()) {
         return Redirect::to_route('post_new')->with_errors($validation)->with_input();
     } else {
         Post::create(array('title' => Input::get('title'), 'body' => Input::get('body'), 'author' => Input::get('author'), 'category_id' => Input::get('category')));
         return Redirect::to_route('post_new')->with('message', 'New Post has been added!');
     }
 }
開發者ID:reeceballano,項目名稱:Mayaten-Blog-Validation-Unique,代碼行數:10,代碼來源:posts.php

示例5: testRelatedContentRecord

 public function testRelatedContentRecord()
 {
     // Create Post
     $post = new Post();
     $post->message = "Test";
     $post->content->container = Yii::app()->user->getModel();
     $this->assertTrue(isset($post->content) && $post->content instanceof Content);
     $this->assertTrue($post->validate());
     $this->assertTrue($post->save());
     $this->assertEquals(1, Content::model()->countByAttributes(array('object_model' => 'Post', 'object_id' => $post->getPrimaryKey())));
 }
開發者ID:ahdail,項目名稱:humhub,代碼行數:11,代碼來源:HActiveRecordContentTest.php

示例6: put_update

 public function put_update()
 {
     $validation = Post::validate(Input::all());
     $s = Input::get('title');
     $t = Str::slug($s);
     $post = Post::find(Input::get('id'));
     if ($validation->fails()) {
         return Redirect::to_route('post_edit', $post->slug)->with_errors($validation)->with_input();
     } else {
         Post::update(Input::get('id'), array('title' => Input::get('title'), 'body' => Input::get('body'), 'author' => Input::get('author'), 'category_id' => Input::get('category')));
         return Redirect::to_route('post_view', $post->slug)->with('message', 'Post has been updated successfully!');
     }
 }
開發者ID:reeceballano,項目名稱:Mayaten-Blog,代碼行數:13,代碼來源:posts.php

示例7: store

 /**
  * Store a newly created post in DB.
  *
  */
 public function store()
 {
     $validator = Post::validate($data = Input::all());
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // We remove quotes from tag_ids with array_map intval
     $tag_ids = array_map('intval', $data['tags']);
     $post = Post::create(['user_id' => $data['user_id'], 'title' => $data['title'], 'content' => $data['content'], 'status' => $data['status']]);
     $post->tags()->sync($tag_ids);
     $post->categories()->attach($data['category']);
     Event::fire('post.created', array($data));
     return Redirect::route('posts.index')->withSuccess(Lang::get('larabase.post_created'));
 }
開發者ID:pogliozzy,項目名稱:larabase,代碼行數:18,代碼來源:PostsController.php

示例8: actionCreate

 public function actionCreate()
 {
     $model = new Post();
     $model->setAttributes($this->getJsonInput());
     if (!$model->validate()) {
         $this->sendResponse(400, CHtml::errorSummary($model));
     } else {
         if (!$model->save(false)) {
             throw new CException('Cannot create a record');
         }
     }
     $model->refresh();
     $this->sendResponse(200, CJSON::encode($model));
 }
開發者ID:jerrylsxu,項目名稱:YiiBackbone,代碼行數:14,代碼來源:PostController.php

示例9: update

 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $validator = Post::validate(Input::all());
     if ($validator->fails()) {
         return Redirect::to('posts/' . $id . '/edit')->withErrors($validator)->withInput(Input::all());
     } else {
         // store
         $post = Post::find($id);
         $post->title = Input::get('title');
         $post->body = Input::get('body');
         $post->save();
         // redirect
         return Redirect::to('posts')->with('message', 'Successfully updated');
     }
 }
開發者ID:shankargiri,項目名稱:Quantum-Vic-La-Trobe-L4,代碼行數:21,代碼來源:PostsController.php

示例10: actionCreate

 /**
  * Creates a new post.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $post = new Post();
     if (isset($_POST['Post'])) {
         $post->attributes = $_POST['Post'];
         if (isset($_POST['previewPost'])) {
             $post->validate();
         } else {
             if (isset($_POST['submitPost']) && $post->save()) {
                 $this->redirect(array('show', 'id' => $post->id));
             }
         }
     }
     $this->render('create', array('post' => $post));
 }
開發者ID:GowthamThangamani,項目名稱:yii-blogdemo-enhanced,代碼行數:19,代碼來源:PostController.php

示例11: update

 public function update()
 {
     $content = Input::all();
     $post = new Post();
     foreach ($content['data'] as $object) {
         if ($post->validate($object)) {
             $posts = Post::find($object['id']);
             $posts->title = $object['title'];
             $posts->content = $object['content'];
             $posts->save();
         } else {
             return Response::json(array('error' => $post->errors()), 500);
         }
     }
     return Response::json(array('error' => false, 'msg' => 'post update'));
 }
開發者ID:nnil4cl,項目名稱:blog,代碼行數:16,代碼來源:PostController.php

示例12: testValidation

 /**
  * Tests SlugBehavior validation.
  *
  * @return void
  * @since 0.1.0
  */
 public function testValidation()
 {
     $defaultAttributes = array('name' => 'Test post post post', 'content' => 'Long enough to conform validation', 'user_id' => 1, 'category_id' => 1, 'slug' => 'admin');
     $post = new \Post();
     $post->setAttributes($defaultAttributes, false);
     if ($post->save(false)) {
         $message = 'Restricted slug hasn\'t been detected by SlugBehavior ' . '(resulting slug: [' . $post->slug . '])';
         $this->fail($message);
     }
     $this->assertTrue(in_array('slugBehavior.restrictedSlug', $post->getErrors('slug'), true));
     $post->setAttributes(array('slug' => '', 'name' => ''), false);
     $post->validate(array());
     if ($post->save(false)) {
         $this->fail('Empty slug hasn\'t been detected by SlugBehavior');
     }
     $this->assertTrue(in_array('slugBehavior.emptySlug', $post->getErrors('slug'), true));
 }
開發者ID:DavBfr,項目名稱:BlogMVC,代碼行數:23,代碼來源:SlugBehaviorTest.php

示例13: actionPost

 public function actionPost()
 {
     $this->forcePostRequest();
     $_POST = Yii::app()->input->stripClean($_POST);
     $post = new Post();
     $post->content->populateByForm();
     $post->message = Yii::app()->request->getParam('message');
     if ($post->validate()) {
         $post->save();
         // Experimental: Auto attach found images urls in message as files
         if (isset(Yii::app()->params['attachFilesByUrlsToContent']) && Yii::app()->params['attachFilesByUrlsToContent'] == true) {
             File::attachFilesByUrlsToContent($post, $post->message);
         }
         $this->renderJson(array('wallEntryId' => $post->content->getFirstWallEntryId()));
     } else {
         $this->renderJson(array('errors' => $post->getErrors()), false);
     }
 }
開發者ID:ahdail,項目名稱:humhub,代碼行數:18,代碼來源:PostController.php

示例14: newPost

 public static function newPost()
 {
     if (Request::isMethod('get')) {
         $groups = DB::table('gsubs')->join('groups', 'groups.group_name', '=', 'gsubs.group_name')->where('gsubs.is_member', 1)->where('gsubs.user_fp', self::userFp())->select('gsubs.*', 'groups.group_title')->get();
         return View::make('board.new_post', ['groups' => $groups]);
     } else {
         $user_fp = self::userFp();
         $input = Input::only('parent_id', 'chan', 'group_name', 'message', 'title', 'source_link');
         Post::validate($input);
         Post::antiflood($user_fp);
         Post::checkDoublePost($user_fp);
         $post = Post::createPost($user_fp, $input);
         if ($post->parent_id == 0) {
             return Redirect::to("p/{$post->id}");
         } else {
             return Redirect::to("p/{$post->parent_id}#p{$post->id}");
         }
     }
 }
開發者ID:libre-net-society,項目名稱:onelon,代碼行數:19,代碼來源:PostController.php

示例15: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $model = new Post();
     if (isset($_POST['Post'])) {
         $model->attributes = $_POST['Post'];
         if (isset($_POST['previewPost'])) {
             $model->validate();
         } else {
             if (isset($_POST['submitPost']) && $model->save()) {
                 if (Yii::app()->user->status == User::STATUS_VISITOR) {
                     Yii::app()->user->setFlash('message', 'Thank you for your post. Your post will be posted once it is approved.');
                     $this->redirect(Yii::app()->homeUrl);
                 }
                 $this->redirect(array('show', 'slug' => $model->slug));
             }
         }
     }
     $this->pageTitle = Yii::t('lan', 'New Post');
     $this->render('create', array('model' => $model));
 }
開發者ID:Greka163,項目名稱:Yii-blog-new,代碼行數:24,代碼來源:PostController.php


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