本文整理汇总了PHP中Cake\ORM\Entity::source方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::source方法的具体用法?PHP Entity::source怎么用?PHP Entity::source使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Entity
的用法示例。
在下文中一共展示了Entity::source方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: url
/**
* Get uploaded image URL.
* Return wrong URL if path config is not under webroot.
* UrlHelper::build generates URL.
*
* @param \Cake\ORM\Entity $entity The entity
* @param string $field The image field name
* @return string
*/
public function url(Entity $entity, $field)
{
$table = TableRegistry::get($entity->source());
$folder = $table->getUploadFolder($entity, $field);
$path = str_replace(WWW_ROOT, '', $folder);
$path .= $entity->get($field);
return $this->Url->build("/{$path}");
}
示例2: afterSave
public function afterSave(Event $event, Entity $entity)
{
$model = substr(strrchr($entity->source(), '.'), 1);
if (!$model) {
$model = $entity->source();
}
$type_id = self::HISTORIES_CREATE;
if (!$entity->isNew()) {
$type_id = self::HISTORIES_UPDATE;
}
$user_id = 0;
// Unknow
debug($this->request->session()->read('Auth.User.id'));
die;
$this->Histories = TableRegistry::get('Histories');
$history = $this->Histories->newEntity(['model' => $model, 'foreign_key' => $entity->id, 'type_id' => $type_id, 'user_id' => $user_id, 'created' => new Time()]);
$this->Histories->save($history);
}
示例3: nestedListFormat
/**
* Format nested list element
*
* Callback method used by The NestableHelper
*
* @param array $data NestableHelper configuration
* @param \Cake\ORM\Entity $entity Entity to format
*/
public function nestedListFormat(array $data, Entity $entity)
{
$displayField = TableRegistry::get($entity->source())->displayField();
$html = '<span class="pull-right p10 pb5">';
$html .= $this->Html->link('<i class="fa fa-edit"></i> ', ['action' => 'edit', $entity->id], ['class' => '', 'escape' => false, 'title' => __d('admin', 'Edit')]);
$html .= $this->Form->postLink('<i class="fa fa-trash-o"></i>', ['action' => 'delete', $entity['id']], ['class' => '', 'title' => __d('admin', 'Delete {0}', Inflector::humanize($entity->source)), 'escape' => false, 'confirm' => __d('admin', 'Are you sure you want to delete #{0} {1}?', $entity->id, $entity->{$displayField})]);
$html .= '</span>';
$html .= '<div class="dd-handle" data-id="' . $entity->id . '">';
if ($entity->active === false) {
$html .= '<span class="text-muted">' . $entity->{$displayField} . '</span>';
$html .= ' <span class="text-danger"><i class="fa fa-ban"></i><em class="sr-only">Non active</em></span>';
} else {
$html .= $entity->{$displayField};
}
$html .= '</div>';
return $html;
}
示例4: testTableFromEntitySource
/**
* Tests that the table can be derived from the entity source if it is present
*
* @return void
*/
public function testTableFromEntitySource()
{
$entity = new Entity();
$entity->source('Articles');
$context = new EntityContext($this->request, ['entity' => $entity]);
$expected = ['id', 'author_id', 'title', 'body', 'published'];
$this->assertEquals($expected, $context->fieldNames());
}
示例5: testSource
/**
* Tests the source method
*
* @return void
*/
public function testSource()
{
$entity = new Entity();
$this->assertNull($entity->source());
$entity->source('foos');
$this->assertEquals('foos', $entity->source());
}
示例6: getUploadPath
public function getUploadPath(Entity $entity, $path, $extension)
{
$replace = array('%uuid' => String::uuid(), '%id' => $entity->id, '%y' => date('Y'), '%m' => date('m'), '/' => DS);
$path = $this->_config['assets_dir'] . DS . Inflector::tableize($entity->source()) . DS . strtr($path, $replace) . '.' . $extension;
return $path;
}
示例7: testIteratorAfterSerializationHydrated
/**
* Test iteration after serialization
*
* @return void
*/
public function testIteratorAfterSerializationHydrated()
{
$query = $this->table->find('all');
$results = unserialize(serialize($query->all()));
// Use a loop to test Iterator implementation
foreach ($results as $i => $row) {
$expected = new \Cake\ORM\Entity($this->fixtureData[$i]);
$expected->isNew(false);
$expected->source($this->table->alias());
$expected->clean();
$this->assertEquals($expected, $row, "Row {$i} does not match");
}
}
示例8: path
/**
* Get the path formatted without its identifiers to upload the file.
* @param \Cake\ORM\Entity $entity The entity that is going to be saved.
* @param array $file The file array
* @param string $path The path
* @return string
*/
private function path(Entity $entity, $file = [], $path = false)
{
// get extension & path
$extension = (new File($file['name'], false))->ext();
$path = trim(str_replace(['/', '\\'], DS, $path), DS);
// handle identifiers
$identifiers = [':model' => strtolower($entity->source()), ':md5' => md5(rand() . uniqid() . time())];
// output
return strtr($path, $identifiers) . '.' . strtolower($extension);
}