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


PHP Table::behaviors方法代码示例

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


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

示例1: testStiTable

 public function testStiTable()
 {
     $this->table->behaviors()->get('StiParent')->config('tableMap', ['Readers' => 'reader_*'], false);
     $this->table->behaviors()->get('StiParent')->config('discriminatorMap', ['*author' => TableRegistry::get('Authors')], false);
     $map = ['reader_1' => 'Readers', 'reader_2' => 'Readers', 'super_author' => 'Authors', 'bestselling-author' => 'Authors', 'other' => 'Users', '' => 'Users'];
     foreach ($map as $discriminator => $alias) {
         $entity = $this->table->newEntity(['discriminator' => $discriminator]);
         $table = $this->table->stiTable($entity);
         $this->assertEquals($alias, $table->alias());
     }
 }
开发者ID:robotusers,项目名称:cakephp-table-inheritance,代码行数:11,代码来源:StiParentBehaviorTest.php

示例2: 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

示例3: resetSlugs

 /**
  * ResetSlugs method.
  *
  * Regenerate all slugs. On large dbs this can take more than 30 seconds - a time
  * limit is set to allow a minimum 100 updates per second as a preventative measure.
  *
  * Note that you should use the Reset behavior if you need additional functionality such
  * as callbacks or timeouts.
  *
  * @param array $params
  * @return bool Success
  */
 public function resetSlugs($params = [])
 {
     if (!$this->_table->hasField($this->_config['field'])) {
         throw new Exception('Table does not have field ' . $this->_config['field']);
     }
     $defaults = ['page' => 1, 'limit' => 100, 'fields' => array_merge([$this->_table->primaryKey()], $this->_config['label']), 'order' => $this->_table->displayField() . ' ASC', 'conditions' => $this->_config['scope'], 'overwrite' => true];
     $params = array_merge($defaults, $params);
     $count = $this->_table->find('all', compact('conditions'))->count();
     $max = ini_get('max_execution_time');
     if ($max) {
         set_time_limit(max($max, $count / 100));
     }
     $this->_table->behaviors()->Slugged->config($params, null, false);
     while ($records = $this->_table->find('all', $params)->toArray()) {
         foreach ($records as $record) {
             $record->isNew(true);
             $options = ['validate' => true, 'fieldList' => array_merge([$this->_table->primaryKey(), $this->_config['field']], $this->_config['label'])];
             if (!$this->_table->save($record, $options)) {
                 throw new Exception(print_r($this->_table->errors(), true));
             }
         }
         $params['page']++;
     }
     return true;
 }
开发者ID:dereuromark,项目名称:cakephp-tools,代码行数:37,代码来源:SluggedBehavior.php

示例4: _buildPropertyMap

 /**
  * Build the map of property => marshalling callable.
  *
  * @param array $data The data being marshalled.
  * @param array $options List of options containing the 'associated' key.
  * @throws \InvalidArgumentException When associations do not exist.
  * @return array
  */
 protected function _buildPropertyMap($data, $options)
 {
     $map = [];
     $schema = $this->_table->schema();
     // Is a concrete column?
     foreach (array_keys($data) as $prop) {
         $columnType = $schema->columnType($prop);
         if ($columnType) {
             $map[$prop] = function ($value, $entity) use($columnType) {
                 return Type::build($columnType)->marshal($value);
             };
         }
     }
     // Map associations
     if (!isset($options['associated'])) {
         $options['associated'] = [];
     }
     $include = $this->_normalizeAssociations($options['associated']);
     foreach ($include as $key => $nested) {
         if (is_int($key) && is_scalar($nested)) {
             $key = $nested;
             $nested = [];
         }
         $assoc = $this->_table->association($key);
         // If the key is not a special field like _ids or _joinData
         // it is a missing association that we should error on.
         if (!$assoc) {
             if (substr($key, 0, 1) !== '_') {
                 throw new \InvalidArgumentException(sprintf('Cannot marshal data for "%s" association. It is not associated with "%s".', $key, $this->_table->alias()));
             }
             continue;
         }
         if (isset($options['forceNew'])) {
             $nested['forceNew'] = $options['forceNew'];
         }
         if (isset($options['isMerge'])) {
             $callback = function ($value, $entity) use($assoc, $nested) {
                 $options = $nested + ['associated' => []];
                 return $this->_mergeAssociation($entity->get($assoc->property()), $assoc, $value, $options);
             };
         } else {
             $callback = function ($value, $entity) use($assoc, $nested) {
                 $options = $nested + ['associated' => []];
                 return $this->_marshalAssociation($assoc, $value, $options);
             };
         }
         $map[$assoc->property()] = $callback;
     }
     $behaviors = $this->_table->behaviors();
     foreach ($behaviors->loaded() as $name) {
         $behavior = $behaviors->get($name);
         if ($behavior instanceof PropertyMarshalInterface) {
             $map += $behavior->buildMarshalMap($this, $map, $options);
         }
     }
     return $map;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:65,代码来源:Marshaller.php

示例5: process

 /**
  * Process action.
  *
  * @param Table $table
  * @param $action
  * @param array $ids
  * @param array $options
  * @return \Cake\Network\Response|void
  */
 public function process(Table $table, $action, array $ids = [], array $options = [])
 {
     $idsCount = count($ids);
     $options = Hash::merge($this->_config, $options);
     $_options = ['messages' => $this->__setupMessages($idsCount)];
     $options = Hash::merge($_options, $options);
     $redirect = $options['redirect'];
     $messages = $options['messages'];
     if (!$action) {
         $this->Flash->error($messages['noAction']);
         return $this->_controller->redirect($redirect);
     }
     if ($idsCount == 0) {
         $this->Flash->error($messages['noChose']);
         return $this->_controller->redirect($redirect);
     }
     $behaviors = $table->behaviors();
     if (!in_array('BulkProcess', $behaviors->loaded())) {
         $behaviors->load('Union/Core.BulkProcess');
     }
     $event = Event::dispatch($this->_getEventName($action, 'bulkBefore'), $this->_controller, ['ids' => $ids]);
     if (is_array($event->result)) {
         $ids = $event->result;
         if (count($ids) == 0) {
             $this->Flash->error($messages['noChose']);
             return $this->_controller->redirect($redirect);
         }
         $messages = $this->__setupMessages(count($ids));
     }
     $process = $table->processAction($action, $ids);
     if ($process) {
         if (!empty($messages[$action])) {
             $message = $messages[$action];
         } else {
             $message = __d('union', '{0} processed', Inflector::humanize($this->_controller->name));
         }
         Event::dispatch($this->_getEventName($action), $this->_controller, ['ids' => $ids]);
         $this->Flash->success($message);
         return $this->_controller->redirect($redirect);
     }
     $this->Flash->error(__d('union', 'An error occurred'));
     return $this->_controller->redirect($redirect);
 }
开发者ID:Cheren,项目名称:union,代码行数:52,代码来源:BulkProcessComponent.php

示例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')]);
     }
 }
开发者ID:burzum,项目名称:cakephp-html-purifier,代码行数:13,代码来源:PurifierShell.php


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