本文整理汇总了PHP中Cake\ORM\Table类的典型用法代码示例。如果您正苦于以下问题:PHP Table类的具体用法?PHP Table怎么用?PHP Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Table类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: belongsToManyJunctionAliases
/**
* Get the array of junction aliases for all the BelongsToMany associations
*
* @param Table $table Table
* @return array junction aliases of all the BelongsToMany associations
*/
public function belongsToManyJunctionAliases(Table $table)
{
$extractor = function ($val) {
return $val->junction()->alias();
};
return array_map($extractor, $table->associations()->type('BelongsToMany'));
}
开发者ID:AmuseXperience,项目名称:api,代码行数:13,代码来源:AssociationFilter.php
示例2: aliasExtractor
/**
* Extract the aliases for associations
*
* @param \Cake\ORM\Table $table object to find associations on
* @param string $assoc association to extract
* @return array
*/
public function aliasExtractor($table, $assoc)
{
$extractor = function ($val) {
return $val->target()->alias();
};
return array_map($extractor, $table->associations()->type($assoc));
}
开发者ID:djamesfar,项目名称:bake,代码行数:14,代码来源:BakeHelper.php
示例3: _prettify
/**
* Method that renders Entity values through Field Handler Factory.
*
* @param Cake\ORM\Entity $entity Entity instance
* @param Cake\ORM\Table|string $table Table instance
* @param array $fields Fields to prettify
* @return void
*/
protected function _prettify(Entity $entity, $table, array $fields = [])
{
if (!$this->__fhf instanceof FieldHandlerFactory) {
$this->__fhf = new FieldHandlerFactory();
}
if (empty($fields)) {
$fields = array_keys($entity->toArray());
}
foreach ($fields as $field) {
// handle belongsTo associated data
if ($entity->{$field} instanceof Entity) {
$tableName = $table->association($entity->{$field}->source())->className();
$this->_prettify($entity->{$field}, $tableName);
}
// handle hasMany associated data
if (is_array($entity->{$field})) {
if (empty($entity->{$field})) {
continue;
}
foreach ($entity->{$field} as $associatedEntity) {
if (!$associatedEntity instanceof Entity) {
continue;
}
$tableName = $table->association($associatedEntity->source())->className();
$this->_prettify($associatedEntity, $tableName);
}
}
$renderOptions = ['entity' => $entity];
$entity->{$field} = $this->__fhf->renderValue($table instanceof Table ? $table->registryAlias() : $table, $field, $entity->{$field}, $renderOptions);
}
}
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:39,代码来源:PrettifyTrait.php
示例4: __construct
public function __construct(Table $table, Entity $entity, $field, array $settings)
{
$this->setRoot(TMP . 'ProfferTests');
$this->setTable($table->alias());
$this->setField($field);
$this->setSeed('proffer_test');
if (isset($settings['thumbnailSizes'])) {
$this->setPrefixes($settings['thumbnailSizes']);
}
$this->setFilename($entity->get($field));
}
开发者ID:edukondaluetg,项目名称:CakePHP3-Proffer,代码行数:11,代码来源:TestPath.php
示例5: __construct
/**
* Constructor
*
* @param \Cake\ORM\Table $table Table who requested the behavior.
* @param array $config Options.
*/
public function __construct(Table $table, array $config = [])
{
parent::__construct($table, $config);
$this->Table = $table;
if ($this->config('created_by')) {
$this->Table->belongsTo('CreatedBy', ['foreignKey' => $this->config('created_by'), 'className' => $this->config('userModel'), 'propertyName' => $this->config('createdByPropertyName')]);
}
if ($this->config('modified_by')) {
$this->Table->belongsTo('ModifiedBy', ['foreignKey' => $this->config('modified_by'), 'className' => $this->config('userModel'), 'propertyName' => $this->config('modifiedByPropertyName')]);
}
}
开发者ID:Tomicapo,项目名称:cakephp-utils,代码行数:17,代码来源:WhoDidItBehavior.php
示例6: _subQuery
/**
* Generates a SQL sub-query for replacing in ORDER BY clause.
*
* @param string $column Name of the column being replaced by this sub-query
* @param string|null $bundle Consider attributes only for a specific bundle
* @return string SQL sub-query statement
*/
protected function _subQuery($column, $bundle = null)
{
$alias = $this->_table->alias();
$pk = $this->_table->primaryKey();
$type = $this->_toolbox->getType($column);
$subConditions = ['EavAttribute.table_alias' => $this->_table->table(), 'EavValues.entity_id' => "{$alias}.{$pk}", 'EavAttribute.name' => $column];
if (!empty($bundle)) {
$subConditions['EavAttribute.bundle'] = $bundle;
}
$subQuery = TableRegistry::get('Eav.EavValues')->find()->contain(['EavAttribute'])->select(["EavValues.value_{$type}"])->where($subConditions)->sql();
return str_replace([':c0', ':c1', ':c2', ':c3'], ['"' . $this->_table->table() . '"', "{$alias}.{$pk}", '"' . $column . '"', '"' . $bundle . '"'], $subQuery);
}
开发者ID:quickapps-plugins,项目名称:eav,代码行数:19,代码来源:OrderScope.php
示例7: increment
public function increment(Table $table, $counter, $identifier)
{
list($alias, $field) = $this->_counterSplit($counter);
$key = $table->primaryKey();
if ($table->alias() !== $alias) {
$key = $table->{$alias}->bindingKey();
$table = TableRegistry::get($alias);
}
$expression = new QueryExpression("{$field} = {$field} + " . $this->_offset);
$conditions = [$key => $identifier] + $this->_conditions;
return $table->updateAll($expression, $conditions);
}
开发者ID:UseMuffin,项目名称:Hits,代码行数:12,代码来源:DefaultStrategy.php
示例8: __construct
/**
* Constructor
*
* @param \Cake\ORM\Table $table Table instance
* @param array $config Configuration
*/
public function __construct(Table $table, array $config = [])
{
$tableAlias = $table->alias();
list($plugin) = pluginSplit($table->registryAlias(), true);
if (isset($config['referenceName'])) {
$tableReferenceName = $config['referenceName'];
} else {
$tableReferenceName = $this->_referenceName($table);
}
$config += ['mainTableAlias' => $tableAlias, 'translationTable' => $plugin . $tableReferenceName . 'Translations', 'hasOneAlias' => $tableAlias . 'Translation'];
parent::__construct($table, $config);
}
开发者ID:adayth,项目名称:cakephp-shadow-translate,代码行数:18,代码来源:ShadowTranslateBehavior.php
示例9: fieldToggle
/**
* Toggle field value.
*
* @param Table|\Cake\ORM\Table $table
* @param string|int $id
* @param string|int $value
* @param string $field
* @throw BadRequestException
* @throw RuntimeException
*/
public function fieldToggle($table, $id, $value, $field = self::TOGGLE_DEFAULT_FIELD)
{
$this->_checkIsAjax();
$this->_checkToggleData($id, $value);
$this->_controller->viewBuilder()->layout('ajax')->templatePath('Common');
$entity = $table->get($id);
$entity->{$field} = !(int) $value;
if ($result = $table->save($entity)) {
$this->_controller->set('record', $result);
$this->_controller->render('toggle');
} else {
throw new RuntimeException(__d('union', 'Failed toggling field {0} to {1}', $field, $entity->{$field}));
}
}
开发者ID:UnionCMS,项目名称:Core,代码行数:24,代码来源:AppComponent.php
示例10: __construct
/**
* Construct the class and setup the defaults
*
* @param Table $table Instance of the table
* @param Entity $entity Instance of the entity data
* @param string $field The name of the upload field
* @param array $settings Array of settings for the upload field
*/
public function __construct(Table $table, Entity $entity, $field, array $settings)
{
if (isset($settings['root'])) {
$this->setRoot($settings['root']);
} else {
$this->setRoot(WWW_ROOT . 'files');
}
$this->setTable($table->alias());
$this->setField($field);
$this->setSeed($this->generateSeed($entity->get($settings['dir'])));
if (isset($settings['thumbnailSizes'])) {
$this->setPrefixes($settings['thumbnailSizes']);
}
$this->setFilename($entity->get($field));
}
开发者ID:edukondaluetg,项目名称:CakePHP3-Proffer,代码行数:23,代码来源:ProfferPath.php
示例11: replaceLinks
/**
* Replaces existing association links between the source entity and the target
* with the ones passed. This method does a smart cleanup, links that are already
* persisted and present in `$targetEntities` will not be deleted, new links will
* be created for the passed target entities that are not already in the database
* and the rest will be removed.
*
* For example, if an article is linked to tags 'cake' and 'framework' and you pass
* to this method an array containing the entities for tags 'cake', 'php' and 'awesome',
* only the link for cake will be kept in database, the link for 'framework' will be
* deleted and the links for 'php' and 'awesome' will be created.
*
* Existing links are not deleted and created again, they are either left untouched
* or updated so that potential extra information stored in the joint row is not
* lost. Updating the link row can be done by making sure the corresponding passed
* target entity contains the joint property with its primary key and any extra
* information to be stored.
*
* On success, the passed `$sourceEntity` will contain `$targetEntities` as value
* in the corresponding property for this association.
*
* This method assumes that links between both the source entity and each of the
* target entities are unique. That is, for any given row in the source table there
* can only be one link in the junction table pointing to any other given row in
* the target table.
*
* Additional options for new links to be saved can be passed in the third argument,
* check `Table::save()` for information on the accepted options.
*
* ### Example:
*
* ```
* $article->tags = [$tag1, $tag2, $tag3, $tag4];
* $articles->save($article);
* $tags = [$tag1, $tag3];
* $articles->association('tags')->replaceLinks($article, $tags);
* ```
*
* `$article->get('tags')` will contain only `[$tag1, $tag3]` at the end
*
* @param \Cake\Datasource\EntityInterface $sourceEntity an entity persisted in the source table for
* this association
* @param array $targetEntities list of entities from the target table to be linked
* @param array $options list of options to be passed to the internal `save`/`delete` calls
* when persisting/updating new links, or deleting existing ones
* @throws \InvalidArgumentException if non persisted entities are passed or if
* any of them is lacking a primary key value
* @return bool success
*/
public function replaceLinks(EntityInterface $sourceEntity, array $targetEntities, array $options = [])
{
$bindingKey = (array) $this->bindingKey();
$primaryValue = $sourceEntity->extract($bindingKey);
if (count(array_filter($primaryValue, 'strlen')) !== count($bindingKey)) {
$message = 'Could not find primary key value for source entity';
throw new InvalidArgumentException($message);
}
return $this->junction()->connection()->transactional(function () use($sourceEntity, $targetEntities, $primaryValue, $options) {
$foreignKey = (array) $this->foreignKey();
$hasMany = $this->source()->association($this->_junctionTable->alias());
$existing = $hasMany->find('all')->where(array_combine($foreignKey, $primaryValue));
$associationConditions = $this->conditions();
if ($associationConditions) {
$existing->contain($this->target()->alias());
$existing->andWhere($associationConditions);
}
$jointEntities = $this->_collectJointEntities($sourceEntity, $targetEntities);
$inserts = $this->_diffLinks($existing, $jointEntities, $targetEntities, $options);
if ($inserts && !$this->_saveTarget($sourceEntity, $inserts, $options)) {
return false;
}
$property = $this->property();
if (count($inserts)) {
$inserted = array_combine(array_keys($inserts), (array) $sourceEntity->get($property));
$targetEntities = $inserted + $targetEntities;
}
ksort($targetEntities);
$sourceEntity->set($property, array_values($targetEntities));
$sourceEntity->dirty($property, false);
return true;
});
}
开发者ID:Mingyangzu,项目名称:PHP-cakephp,代码行数:82,代码来源:BelongsToMany.php
示例12: initialize
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->table('balance');
$this->displayField('id');
$this->primaryKey('id');
}
开发者ID:borisknot,项目名称:cmanage,代码行数:13,代码来源:BalanceTable.php
示例13: checkTable
/**
* Do some checks on the table which has been passed to make sure that it has what we need
*
* @param string $table The table
* @return void
*/
protected function checkTable($table)
{
try {
$this->Table = $this->loadModel($table);
} catch (Exception $e) {
$this->out(__('<error>' . $e->getMessage() . '</error>'));
exit;
}
if (get_class($this->Table) === 'AppModel') {
$this->out(__('<error>The table could not be found, instance of AppModel loaded.</error>'));
exit;
}
if (!$this->Table->hasBehavior('Proffer')) {
$out = __("<error>The table '" . $this->Table->alias() . "' does not have the Proffer behavior attached.</error>");
$this->out($out);
exit;
}
$config = $this->Table->behaviors()->Proffer->config();
foreach ($config as $field => $settings) {
if (!$this->Table->hasField($field)) {
$out = __("<error>The table '" . $this->Table->alias() . "' does not have the configured upload field in it's schema.</error>");
$this->out($out);
exit;
}
if (!$this->Table->hasField($settings['dir'])) {
$out = __("<error>The table '" . $this->Table->alias() . "' does not have the configured dir field in it's schema.</error>");
$this->out($out);
exit;
}
}
}
开发者ID:rohanpande,项目名称:CakePHP3-Proffer,代码行数:37,代码来源:ProfferShell.php
示例14: _initializeSchema
/**
* @param \Cake\Database\Schema\Table $table Table schema
* @return \Cake\Database\Schema\Table
*/
protected function _initializeSchema(Schema $table)
{
$table->columnType('payload', 'serialize');
$table->columnType('options', 'serialize');
$table->columnType('history', 'json');
return parent::_initializeSchema($table);
}
开发者ID:uafrica,项目名称:delayed-jobs,代码行数:11,代码来源:DelayedJobsTable.php
示例15: beforeFind
/**
* @param \Cake\Event\Event $event
* @param \Cake\ORM\Query $query
* @param \ArrayObject $options
* @param bool $primary
* @return void
*/
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
{
if (!$primary && !$this->_config['recursive']) {
return;
}
$field = $this->_config['field'];
if (!$field) {
return;
}
$query->find('hashed');
$idField = $this->_primaryKey;
if ($primary && $field === $idField) {
$query->traverseExpressions(function ($expression) {
if (method_exists($expression, 'getField') && ($expression->getField() === $this->_primaryKey || $expression->getField() === $this->_table->alias() . '.' . $this->_primaryKey)) {
$expression->setValue($this->decodeHashid($expression->getValue()));
}
return $expression;
});
}
if (!$this->_config['recursive']) {
return;
}
foreach ($this->_table->associations() as $association) {
if ($association->target()->hasBehavior('Hashid') && $association->finder() === 'all') {
$association->finder('hashed');
}
}
}
开发者ID:dereuromark,项目名称:cakephp-hashid,代码行数:35,代码来源:HashidBehavior.php
示例16: testUnaryExpression
/**
* test WHERE conditions against unary expression.
*
* @return void
*/
public function testUnaryExpression()
{
$this->table->addColumn('user-birth-date', ['type' => 'date'], false);
$first = $this->table->get(1);
$first->set('user-birth-date', time());
$this->table->save($first);
$second = $this->table->find('all', ['eav' => true])->where(['user-birth-date IS' => null])->order(['id' => 'ASC'])->first();
$this->assertTrue(!empty($second) && $second->get('id') == 2);
}
开发者ID:quickapps-plugins,项目名称:eav,代码行数:14,代码来源:EavBehaviorTest.php
示例17: testSendNewPasswordEmail
/**
* testSendNewPasswordEmail
*
* @return void
*/
public function testSendNewPasswordEmail()
{
$user = $this->Users->get(1);
$this->Mailer->expects($this->once())->method('to')->with('[email protected]')->will($this->returnSelf());
$this->Mailer->expects($this->once())->method('subject')->with('Your new password')->will($this->returnSelf());
$this->Mailer->expects($this->once())->method('template')->with('Burzum/UserTools.Users/new_password')->will($this->returnSelf());
$this->Mailer->expects($this->once())->method('set')->with('user', $user)->will($this->returnSelf());
$this->Mailer->sendNewPasswordEmail($user);
}
开发者ID:burzum,项目名称:cakephp-user-tools,代码行数:14,代码来源:UsersMailerTest.php
示例18: __setForLayout
/**
* Setup modules for layout.
*
* @return void
*/
private function __setForLayout()
{
$positions = $this->Theme->getThemePositions();
$theme = Inflector::underscore(Configure::read('Theme.' . Theme::CLIENT_FRONT_END));
foreach ($positions as $position) {
$cacheKey = $theme . '_' . $position;
$modules = $this->_table->find()->where(['position' => $position])->order(['ordering' => 'ASC'])->cache($cacheKey, 'positions')->toArray();
if (!empty($modules)) {
$this->_modulesForLayout[$position] = $modules;
}
}
$this->_controller->set('module_for_layout', $this->_modulesForLayout);
}
开发者ID:Cheren,项目名称:union,代码行数:18,代码来源:ModuleComponent.php
示例19: testFind
public function testFind()
{
$entities = [];
foreach ($this->entityMap as $discriminator => $class) {
$data = ['discriminator' => $discriminator];
$entities[] = $this->table->newEntity($data);
}
$this->table->saveMany($entities);
$found = $this->table->find()->toArray();
$this->assertCount(6, $found);
foreach ($found as $entity) {
$class = $this->entityMap[$entity->discriminator];
$this->assertInstanceOf($class, $entity);
}
}
开发者ID:robotusers,项目名称:cakephp-table-inheritance,代码行数:15,代码来源:StiParentBehaviorTest.php
示例20: basepath
/**
* Returns the basepath for the current field/data combination.
* If a `path` is specified in settings, then that will be used as
* the replacement pattern
*
* @return string
* @throws LogicException if a replacement is not valid for the current dataset
*/
public function basepath()
{
$defaultPath = 'webroot{DS}files{DS}{model}{DS}{field}{DS}';
$path = Hash::get($this->settings, 'path', $defaultPath);
if (strpos($path, '{primaryKey}') !== false) {
if ($this->entity->isNew()) {
throw new LogicException('{primaryKey} substitution not allowed for new entities');
}
if (is_array($this->table->primaryKey())) {
throw new LogicException('{primaryKey} substitution not valid for composite primary keys');
}
}
$replacements = ['{primaryKey}' => $this->entity->get($this->table->primaryKey()), '{model}' => $this->table->alias(), '{relatedModel}' => $this->entity->model, '{table}' => $this->table->table(), '{field}' => $this->field, '{time}' => time(), '{microtime}' => microtime(), '{DS}' => DIRECTORY_SEPARATOR];
return str_replace(array_keys($replacements), array_values($replacements), $path);
}
开发者ID:gintonicweb,项目名称:images,代码行数:23,代码来源:PolymorphicProcessor.php
注:本文中的Cake\ORM\Table类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论