本文整理汇总了PHP中Cake\ORM\Table::addBehavior方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::addBehavior方法的具体用法?PHP Table::addBehavior怎么用?PHP Table::addBehavior使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Table
的用法示例。
在下文中一共展示了Table::addBehavior方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCamposEmArray
/**
* testCamposEmArray
*
* @retun void
* @access public
*/
public function testCamposEmArray()
{
$this->Noticias->addBehavior("CakePtbr.AjusteData", ["autorizado_em", "publicado_em"]);
$noticia = $this->__preparaNoticia("25/03/15 16:42:05");
$this->assertEquals("2015-03-22", $noticia->get("autorizado_em"));
$this->assertEquals("2015-03-25 16:42:05", $noticia->get("publicado_em"));
}
示例2: setUp
public function setUp()
{
parent::setUp();
$this->entityMap = ['Authors' => Author::class, 'Users' => User::class, 'Editors' => Editor::class, 'Readers' => Reader::class, 'Subscribers' => Reader::class, '' => User::class];
$this->table = TableRegistry::get('Users');
$this->table->entityClass(User::class);
$authors = TableRegistry::get('Authors', ['table' => 'users']);
$editors = TableRegistry::get('Editors', ['table' => 'users']);
$readers = TableRegistry::get('Readers', ['table' => 'users']);
$authors->addBehavior('Robotusers/TableInheritance.Sti');
$editors->addBehavior('Robotusers/TableInheritance.Sti');
$readers->addBehavior('Robotusers/TableInheritance.Sti');
$this->table->addBehavior('Robotusers/TableInheritance.StiParent', ['discriminatorMap' => ['Authors' => 'Authors', 'Editors' => 'Editors'], 'tableMap' => ['Readers' => ['Readers', 'Subscribers']]]);
$authors->entityClass(Author::class);
$editors->entityClass(Editor::class);
$readers->entityClass(Reader::class);
}
示例3: loadUserBehaviour
/**
* Loads the User behavior for the user model if it is not already loaded
*
* @return void
*/
public function loadUserBehaviour()
{
if ($this->_config['autoloadBehavior'] && !$this->UserTable->hasBehavior('UserTools.User')) {
if (is_array($this->_config['autoloadBehavior'])) {
$this->UserTable->addBehavior('Burzum/UserTools.User', $this->_config['autoloadBehavior']);
} else {
$this->UserTable->addBehavior('Burzum/UserTools.User');
}
}
}
示例4: setUp
/**
* Initial Tree
*
* - One
* -- One-SubA
* - Two
* -- Two-SubA
* --- Two-SubA-1
* ---- Two-SubA-1-1
* - Three
* - Four
* -- Four-SubA
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->Tree = new TreeHelper(new View(null));
$this->Table = TableRegistry::get('AfterTrees');
$this->Table->addBehavior('Tree');
//$this->Table->truncate();
$connection = ConnectionManager::get('test');
$sql = $this->Table->schema()->truncateSql($connection);
foreach ($sql as $snippet) {
$connection->execute($snippet);
}
//$this->Table->deleteAll(array());
$data = [['name' => 'One'], ['name' => 'Two'], ['name' => 'Three'], ['name' => 'Four'], ['name' => 'One-SubA', 'parent_id' => 1], ['name' => 'Two-SubA', 'parent_id' => 2], ['name' => 'Four-SubA', 'parent_id' => 4], ['name' => 'Two-SubA-1', 'parent_id' => 6], ['name' => 'Two-SubA-1-1', 'parent_id' => 8]];
foreach ($data as $row) {
$row = new Entity($row);
$this->Table->save($row);
}
}
示例5: testAddBehaviorDuplicate
/**
* Test adding a behavior that is a duplicate.
*
* @return void
*/
public function testAddBehaviorDuplicate()
{
$table = new Table(['table' => 'articles']);
$this->assertNull($table->addBehavior('Sluggable', ['test' => 'value']));
$this->assertNull($table->addBehavior('Sluggable', ['test' => 'value']));
try {
$table->addBehavior('Sluggable', ['thing' => 'thing']);
$this->fail('No exception raised');
} catch (\RuntimeException $e) {
$this->assertContains('The "Sluggable" alias has already been loaded', $e->getMessage());
}
}
示例6: _loadBehavior
/**
* Loads the purifier behavior for the given table if not already attached.
*
* @param \Cake\ORM\Table $table Table object.
* @param array Set of fields to sanitize
* @return void
*/
protected function _loadBehavior(Table $table, $fields)
{
if (!in_array('HtmlPurifier', $table->behaviors()->loaded())) {
$table->addBehavior('Burzum/HtmlPurifier.HtmlPurifier', ['fields' => $fields, 'purifierConfig' => $this->param('config')]);
}
}
示例7: setUp
/**
* startTest
*
* @retun void
* @access public
*/
public function setUp()
{
$this->Produtos = TableRegistry::get('CakePtbr.Produtos');
$this->Produtos->addBehavior("CakePtbr.AjusteFloat");
}
示例8: setUp
/**
* setUp().
*
* @return void
*/
public function setUp()
{
$this->table = TableRegistry::get('Dummy');
$this->table->addBehavior('Eav.Eav');
}
示例9: testAddBehavior
/**
* Test adding a behavior to a table.
*
* @return void
*/
public function testAddBehavior()
{
$mock = $this->getMock('Cake\\ORM\\BehaviorRegistry', [], [], '', false);
$mock->expects($this->once())->method('load')->with('Sluggable');
$table = new Table(['table' => 'articles', 'behaviors' => $mock]);
$table->addBehavior('Sluggable');
}