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