当前位置: 首页>>代码示例>>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;未经允许,请勿转载。