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


PHP Entity::accessible方法代码示例

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


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

示例1: beforeSave

 public function beforeSave(Event $event, Entity $entity)
 {
     $get_user_id_function = $this->config('get_user_id_function');
     if (!empty($get_user_id_function)) {
         $user_id = call_user_func($get_user_id_function);
         if ($entity->isNew() && $entity->accessible('created_by')) {
             $entity->created_by = $user_id;
         }
         if (!$entity->isNew() && $entity->accessible('modified_by')) {
             $entity->modified_by = $user_id;
         }
     }
 }
开发者ID:alaxos,项目名称:cakephp3-libs,代码行数:13,代码来源:UserLinkBehavior.php

示例2: beforeSave

 public function beforeSave(Event $event, Entity $entity)
 {
     /*
      * Save Model only after a commit when the ancestors table has been saved as well
      * -> start a transaction
      */
     $table = $event->subject();
     $connection = $table->connection();
     $connection->begin();
     /*
      * Get existing parent_id to check if the node in moved in the tree
      */
     $this->has_new_parent = false;
     if (!$entity->isNew()) {
         /*
          * If the entity is not a new one, it may have been moved in the tree
          */
         $primaryKey = $table->schema()->primaryKey();
         $primaryKey = count($primaryKey) == 1 ? $primaryKey[0] : $primaryKey;
         $parent_id_fieldname = $this->config('model_parent_id_fieldname');
         if ($entity->accessible($parent_id_fieldname)) {
             $parent_id = $entity->{$parent_id_fieldname};
             $id = $entity->{$primaryKey};
             $existing_entity = $table->get($id);
             if ($parent_id != $existing_entity->{$parent_id_fieldname}) {
                 /*
                  * Node has been moved in the Tree
                  */
                 $this->has_new_parent = true;
             }
         } else {
             throw new \Exception(__d('alaxos', 'the parent field is not accesible'));
         }
     }
     return true;
 }
开发者ID:alaxos,项目名称:cakephp3-libs,代码行数:36,代码来源:AncestorBehavior.php

示例3: testMergeWithCreate

 /**
  * Test merge with validation and create or update validation rules
  *
  * @return void
  */
 public function testMergeWithCreate()
 {
     $data = ['title' => 'My title', 'author_id' => 'foo'];
     $marshall = new Marshaller($this->articles);
     $entity = new Entity(['title' => 'Foo', 'body' => 'My Content', 'author_id' => 1]);
     $entity->accessible('*', true);
     $entity->isNew(true);
     $entity->clean();
     $this->articles->validator()->requirePresence('thing', 'update')->add('author_id', 'numeric', ['rule' => 'numeric', 'on' => 'update']);
     $expected = clone $entity;
     $result = $marshall->merge($expected, $data, []);
     $this->assertEmpty($result->errors('author_id'));
     $this->assertEmpty($result->errors('thing'));
     $entity->clean();
     $entity->isNew(false);
     $result = $marshall->merge($entity, $data, []);
     $this->assertNotEmpty($result->errors('author_id'));
     $this->assertNotEmpty($result->errors('thing'));
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:24,代码来源:MarshallerTest.php

示例4: testDebugInfo

 /**
  * Tests __debugInfo
  *
  * @return void
  */
 public function testDebugInfo()
 {
     $entity = new Entity(['foo' => 'bar'], ['markClean' => true]);
     $entity->somethingElse = 'value';
     $entity->accessible('name', true);
     $entity->virtualProperties(['baz']);
     $entity->dirty('foo', true);
     $entity->errors('foo', ['An error']);
     $entity->source('foos');
     $result = $entity->__debugInfo();
     $expected = ['foo' => 'bar', 'somethingElse' => 'value', '[new]' => true, '[accessible]' => ['*' => true, 'name' => true], '[dirty]' => ['somethingElse' => true, 'foo' => true], '[original]' => [], '[virtual]' => ['baz'], '[errors]' => ['foo' => ['An error']], '[repository]' => 'foos'];
     $this->assertSame($expected, $result);
 }
开发者ID:jeremyheaton,项目名称:ultiswap,代码行数:18,代码来源:EntityTest.php

示例5: testDebugInfo

 /**
  * Tests __debugInfo
  *
  * @return void
  */
 public function testDebugInfo()
 {
     $entity = new Entity(['foo' => 'bar'], ['markClean' => true]);
     $entity->accessible('name', true);
     $entity->virtualProperties(['baz']);
     $entity->dirty('foo', true);
     $entity->errors('foo', ['An error']);
     $entity->source('foos');
     $result = $entity->__debugInfo();
     $expected = ['new' => true, 'accessible' => ['*' => true, 'name' => true], 'properties' => ['foo' => 'bar'], 'dirty' => ['foo' => true], 'original' => [], 'virtual' => ['baz'], 'errors' => ['foo' => ['An error']], 'repository' => 'foos'];
     $this->assertSame($expected, $result);
 }
开发者ID:RogerSchmeier,项目名称:Webtruck,代码行数:17,代码来源:EntityTest.php

示例6: testMergeAssociationWithfieldList

 /**
  * Tests merging associated data with a fieldList
  *
  * @return void
  */
 public function testMergeAssociationWithfieldList()
 {
     $user = new Entity(['username' => 'mark', 'password' => 'secret']);
     $entity = new Entity(['tile' => 'My Title', 'user' => $user]);
     $user->accessible('*', true);
     $entity->accessible('*', true);
     $data = ['body' => 'My Content', 'something' => 'else', 'user' => ['password' => 'not a secret', 'extra' => 'data']];
     $marshall = new Marshaller($this->articles);
     $marshall->merge($entity, $data, ['fieldList' => ['something'], 'associated' => ['Users' => ['fieldList' => ['extra']]]]);
     $this->assertNull($entity->body);
     $this->assertEquals('else', $entity->something);
     $this->assertSame($user, $entity->user);
     $this->assertEquals('mark', $entity->user->username);
     $this->assertEquals('secret', $entity->user->password);
     $this->assertEquals('data', $entity->user->extra);
     $this->assertTrue($entity->dirty('user'));
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:22,代码来源:MarshallerTest.php

示例7: testMergeBelongsToManyEntitiesFromIds

 /**
  * Tests that merging data to an entity containing belongsToMany and _ids
  * will just overwrite the data
  *
  * @return void
  */
 public function testMergeBelongsToManyEntitiesFromIds()
 {
     $entity = new Entity(['title' => 'Haz tags', 'body' => 'Some content here', 'tags' => [new Entity(['id' => 1, 'name' => 'Cake']), new Entity(['id' => 2, 'name' => 'PHP'])]]);
     $data = ['title' => 'Haz moar tags', 'tags' => ['_ids' => [1, 2, 3]]];
     $entity->accessible('*', true);
     $marshall = new Marshaller($this->articles);
     $result = $marshall->merge($entity, $data, ['Tags']);
     $this->assertCount(3, $result->tags);
     $this->assertInstanceOf('Cake\\ORM\\Entity', $result->tags[0]);
     $this->assertInstanceOf('Cake\\ORM\\Entity', $result->tags[1]);
     $this->assertInstanceOf('Cake\\ORM\\Entity', $result->tags[2]);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:18,代码来源:MarshallerTest.php


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