本文整理汇总了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;
}
}
}
示例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;
}
示例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'));
}
示例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);
}
示例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);
}
示例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'));
}
示例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]);
}