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


PHP Post::setAttributes方法代碼示例

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


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

 public function testModel()
 {
     $model = Post::model();
     $this->assertTrue($model instanceof Post);
     $this->assertTrue($model->dbConnection === $this->_connection);
     $this->assertTrue($model->dbConnection->active);
     $this->assertEquals('posts', $model->tableName());
     $this->assertEquals('id', $model->tableSchema->primaryKey);
     $this->assertTrue($model->tableSchema->sequenceName === '');
     $this->assertEquals(array(), $model->attributeLabels());
     $this->assertEquals('Id', $model->getAttributeLabel('id'));
     $this->assertEquals('Author Id', $model->getAttributeLabel('author_id'));
     $this->assertTrue($model->getActiveRelation('author') instanceof CBelongsToRelation);
     $this->assertTrue($model->tableSchema instanceof CDbTableSchema);
     $this->assertTrue($model->commandBuilder instanceof CDbCommandBuilder);
     $this->assertTrue($model->hasAttribute('id'));
     $this->assertFalse($model->hasAttribute('comments'));
     $this->assertFalse($model->hasAttribute('foo'));
     $this->assertEquals(array('id' => null, 'title' => null, 'create_time' => null, 'author_id' => null, 'content' => null), $model->attributes);
     $post = new Post();
     $this->assertNull($post->id);
     $this->assertNull($post->title);
     $post->setAttributes(array('id' => 3, 'title' => 'test title'));
     $this->assertNull($post->id);
     $this->assertEquals('test title', $post->title);
 }
開發者ID:mjrouser,項目名稱:cityapi,代碼行數:26,代碼來源:CActiveRecordTest.php

示例3: testBehavior

 /**
  * Tests correct date/time setting.
  *
  * @return void
  * @since 0.1.0
  */
 public function testBehavior()
 {
     // mocking failed :(
     /*$post = Stub::Make(
           'Post',
           array(
               'insert' => function () {
                   return true;
               },
               'update' => function () {
                   return true;
               },
               'name' => 'Dummy name',
               'content' => 'Dummiest content',
               'user_id' => 1,
               'category_id' => 1,
           )
       );*/
     $post = new \Post();
     $post->setAttributes(array('name' => 'Dummy name', 'content' => 'Dummiest content', 'user_id' => 1, 'category_id' => 1), false);
     $this->assertNull($post->created);
     $post->save();
     $dt = new \DateTime();
     $this->assertSame($dt->format(\DateTime::ISO8601), $post->created);
     usleep(1.1 * 1000 * 1000);
     $post->save();
     $this->assertSame($dt->format(\DateTime::ISO8601), $post->created);
 }
開發者ID:DavBfr,項目名稱:BlogMVC,代碼行數:34,代碼來源:DateTimeCreatedBehaviorTest.php

示例4: add

 public function add($attr, $image)
 {
     $model = new Post();
     $model->setAttributes($attr);
     $model->date = time();
     $model->post_comment_count = 0;
     $model->post_like_count = 0;
     $image_url = null;
     if (isset($image)) {
         $image_url = UploadHelper::getUrlUploadSingleImage($image, $attr['user_id']);
     }
     $location = new Location();
     $location->longitude = $attr['lng'];
     $location->latitude = $attr['lat'];
     $location->name = $attr['name'];
     $location->save(FALSE);
     $model->image = $image_url;
     $model->location_id = $location->location_id;
     if ($model->save(FALSE)) {
         $subject_arr = json_decode($attr['subject'], true);
         foreach ($subject_arr as $item) {
             $subject_post = new PostSubject();
             $subject_post->post_id = $model->post_id;
             $subject_post->subject_id = $item;
             $subject_post->save(FALSE);
         }
         return TRUE;
     }
     return FALSE;
 }
開發者ID:uethackathon,項目名稱:uethackathon2015_team4,代碼行數:30,代碼來源:Post.php

示例5: 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

示例6: test_should_update_datetime_correctly

 public function test_should_update_datetime_correctly()
 {
     $params = array('title' => 'Expiring salutation', 'body' => 'Expiring Hello world!', 'expires_at(1i)' => '2007', 'expires_at(2i)' => '10', 'expires_at(3i)' => '15', 'expires_at(4i)' => '17', 'expires_at(5i)' => '30');
     $Post = new Post();
     $Post->setAttributes($params);
     $this->assertTrue($Post->save());
     $Post->reload();
     $this->assertEqual($Post->get('expires_at'), '2007-10-15 17:30:00');
 }
開發者ID:bermi,項目名稱:akelos,代碼行數:9,代碼來源:type_casting.php

示例7: testCacheInvalidation

 /**
  * Verifies that main cache key resets every time post is edited.
  *
  * @return void
  * @since 0.1.0
  */
 public function testCacheInvalidation()
 {
     $value = \Yii::app()->cacheHelper->getPostsCacheTokenValue();
     $post = new \Post();
     $attrs = array('name' => 'just a name', 'slug' => 'just-a-name', 'content' => 'Dummy content', 'created' => '2010-05-05 12:12:12', 'user_id' => 1, 'category_id' => 1);
     $post->setAttributes($attrs, false);
     $post->save();
     $this->assertNotSame($value, $value = \Yii::app()->cacheHelper->getPostsCacheTokenValue());
     $post->delete();
     $this->assertNotSame($value, $value = \Yii::app()->cacheHelper->getPostsCacheTokenValue());
 }
開發者ID:EhteshamMehmood,項目名稱:BlogMVC,代碼行數:17,代碼來源:PostTest.php

示例8: 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 (Yii::app()->request->isPostRequest) {
         if (isset($_POST['Post'])) {
             $post->setAttributes($_POST['Post']);
         }
         if ($post->save()) {
             $this->redirect(array('show', 'id' => $post->id));
         }
     }
     $this->render('create', array('post' => $post));
 }
開發者ID:kdambekalns,項目名稱:framework-benchs,代碼行數:17,代碼來源:PostController.php

示例9: 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

示例10: actionIndex

 /**
  * Управление записями.
  *
  * @return void
  */
 public function actionIndex()
 {
     $model = new Post('search');
     $model->unsetAttributes();
     // clear any default values
     $model->comment_status = true;
     if (Yii::app()->getRequest()->getParam('Post')) {
         $model->setAttributes(Yii::app()->getRequest()->getParam('Post'));
     }
     $this->render('index', array('model' => $model));
 }
開發者ID:sherifflight,項目名稱:yupe,代碼行數:16,代碼來源:PostBackendController.php

示例11: actionIndex

 /**
  * Управление записями.
  *
  * @return void
  */
 public function actionIndex()
 {
     $model = new Post('search');
     $model->unsetAttributes();
     // clear any default values
     if (Yii::app()->getRequest()->getParam('Post')) {
         $model->setAttributes(Yii::app()->getRequest()->getParam('Post'));
     }
     $this->render('index', ['model' => $model]);
 }
開發者ID:syrexby,項目名稱:domovoishop.by,代碼行數:15,代碼來源:PostBackendController.php


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