本文整理汇总了PHP中ModelBehavior::setup方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelBehavior::setup方法的具体用法?PHP ModelBehavior::setup怎么用?PHP ModelBehavior::setup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelBehavior
的用法示例。
在下文中一共展示了ModelBehavior::setup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
/**
* setup method
*
* @param Model $model
* @param array $config
* @return void
*/
public function setup(Model $model, $config = array()) {
parent::setup($model, $config);
if (isset($config['mangle'])) {
$config['mangle'] .= ' mangled';
}
$this->settings[$model->alias] = array_merge(array('beforeFind' => 'on', 'afterFind' => 'off'), $config);
}
示例2: setup
public function setup(Model $model, $config = array())
{
parent::setup($model, $config);
if (!isset($this->settings[$model->alias])) {
$this->settings[$model->alias] = $this->_defaults;
}
$this->settings[$model->alias] = array_merge($this->settings[$model->alias], $config);
}
示例3: setup
/**
* Setup this behavior with the specified configuration settings.
*
* @param Model $model Model using this behavior
* @param array $config Configuration settings for $model
* @return void
*/
public function setup(Model $model, $config = array())
{
parent::setup($model, $config);
foreach ($config as $field) {
$this->settings[$model->alias]['fields'][] = $field;
}
$this->validateDb($model);
}
示例4: setup
/**
* Setup the behaviour and merge in the settings. Check that the model has the
* required fields
*
* @param Model $model
* @param array $config
*/
public function setup(Model $model, $config = array())
{
parent::setup($model, $config);
$this->settings[$model->alias] = array_merge($this->defaults, $config);
$this->modelAlias = $model->alias;
$this->hasField($model);
$this->checkPrefix($model);
if (!ClassRegistry::isKeySet($this->settings[$model->alias]['statusModel'])) {
$this->Status = ClassRegistry::init($this->settings[$model->alias]['statusModel']);
}
}
示例5: setup
/**
* Setup
* @param Model $model
* @param array $config
* @throws ErrorException
*/
public function setup(Model $model, $config = array())
{
parent::setup($model, $config);
if (empty($config['list'])) {
throw new ErrorException('The list id is necessary to save the contact.');
}
$this->listId = $config['list'];
// If key fields exists
if (!empty($config['fields'])) {
$this->fields = $config['fields'];
}
$this->Contact = new MediaPostContact(null);
}
示例6: setup
/**
* SetUp behavior
*
* @param object $model instance of model
* @param array $config array of configuration settings.
* @return void
*/
public function setup(Model $model, $config = array())
{
if (isset($config['model'])) {
$this->__model = $config['model'];
} else {
$this->__model = $model->name;
}
if (isset($config['field'])) {
$this->__field = $config['field'];
} else {
$this->__field = 'key';
}
parent::setup($model, $config);
}
示例7: setup
public function setup(Model $Model, $config = [])
{
$this->_settings = $config;
$this->_Grid = $Model->getDataSource()->getMongoDb()->getGridFS();
return parent::setup($Model, $this->_settings);
}
示例8: setup
/**
* Initialize Serializable Behavior
*
* @param Model $Model Model which uses behaviour
* @param array $config Behaviour config
*/
public function setup(Model $Model, $config = array())
{
parent::setup($Model, $config);
$this->config[$Model->alias] = $config + (array) Configure::read('Serializable') + array('fields' => array(), 'serialize' => 'serialize', 'unserialize' => 'unserialize', 'aliases' => array(), 'merge' => false);
}
示例9: setup
/**
* Sets up a connection using passed settings
*
* ### Config
* - `config` The name of an existing Cache configuration to use. Default is 'default'
* - `clearOnSave` Whether or not to delete the cache on saves
* - `clearOnDelete` Whether or not to delete the cache on deletes
* - `auto` Automatically cache or look for `'cache'` in the find conditions
* where the key is `true` or a duration
*
* @param Model $model The calling model
* @param array $config Configuration settings
* @return void
* @see Cache::config()
*/
public function setup(Model $model, $config = array())
{
$settings = array_merge($this->_defaults, $config);
// Modified and set config for CachedSoure by behavior setting
$ds = ConnectionManager::getDataSource($model->useDbConfig);
$dsConfig = array_merge($ds->config, array('original' => $model->useDbConfig, 'datasource' => 'Cache.CachedSource', 'config' => $settings['config'], 'map' => $settings['map'], 'gzip' => $settings['gzip']));
if (!in_array('cached', ConnectionManager::sourceList())) {
ConnectionManager::create('cached', $dsConfig);
} else {
$ds = ConnectionManager::getDataSource('cached');
$ds->setConfig($dsConfig);
}
// Merge behavior setting
if (!isset($this->settings[$model->alias])) {
$this->settings[$model->alias] = $settings;
} else {
$this->settings[$model->alias] = array_merge($this->settings[$model->alias], $settings);
}
return parent::setup($model, $config);
}
示例10: setup
/**
* Initialize Caching Behavior
*
* @param Model $Model Model which uses behaviour
* @param array $config Behaviour config
*/
public function setup(Model $Model, $config = array())
{
parent::setup($Model, $config);
$this->config[$Model->alias] = $config + array('cache' => 'default', 'cachedObject' => 'Caching.CachedObject');
}
示例11: setup
/**
* Setup this behavior with the specified configuration settings.
*
* @param Model $model Model using this behavior
* @param array $config Configuration settings for $model
* @return void
*/
public function setup(Model $model, $config = array())
{
parent::setup($model, $config);
$model->loadModels(['RolesRoomsUser' => 'Rooms.RolesRoomsUser', 'Room' => 'Rooms.Room', 'Space' => 'Rooms.Space']);
}
示例12: setup
public function setup(\Model $model, $config = array())
{
return parent::setup($model, $config);
}
示例13: setup
/**
* Populates the settings property of the behavior in an array in the form:
*
* array(
* $model->alias => array(
* $habtmAlias => array(
* 'counterCache' => '<counterCache field name>'
* 'counterScope' => array('field' => 'value') // Usual CakePHP condition
* 'underCounterCache' => '<counterTree field name>'
* ),
* ),
* )
*
* @param AppModel $model
* @param array $config Configuration is very flexible, for example:
* - Just attach and it will do counter caching for all hatbm
* associated models that have the counterCache field. E.g.
*
* var $actsAs = array('HabtmCounterCache.HabtmCounterCache');
*
* - Specify counterCache, counterScope and/or underCounterCache keys
* in the configuration options when you attach the behavior for these
* settings to be applied to all habtm associations. E.g.
*
* var $actsAs = array(
* 'HabtmCounterCache.HabtmCounterCache' => array(
* 'counterScope' => array('active' => 1)
* ),
* );
*
* - Introduce habtm association specific counterCache and counterScope
* settings by using the habtm alias as the key E.g.
*
* var $actsAs = array(
* 'HabtmCounterCache.HabtmCounterCache' => array(
* 'Tag' => array(
* 'counterCache' => 'weight'
* )
* ),
* );
*/
public function setup(\Model $model, $config = array())
{
parent::setup($model, $config);
// Work out the default names of what we expect the counter cache and under
// counter cache fields to be. These will be overridden if specified in the
// config.
$defaultCounterCacheField = Inflector::underscore($model->alias) . '_count';
$defaultUnderCounterCacheField = 'under_' . $defaultCounterCacheField;
// Set up the default settings for this model. Default counterCache field is
// post_count for Post model, no counterScope.
$defaults = array('counterCache' => $defaultCounterCacheField, 'counterScope' => null, 'underCounterCache' => $defaultUnderCounterCacheField);
// Get the settings for all habtm associations, if set.
$allHabtmSettings = $this->_config2settings($config);
$allHabtmSettings = array_merge($defaults, $allHabtmSettings);
// Iterate through the habtms of the model, assigning the settings to the
// settings property of the behavior
foreach ($model->hasAndBelongsToMany as $habtmAlias => $habtmAssocData) {
$habtmSpecificSettings = array();
// Check whether habtm specific settings have been set for this alias
if (isset($config[$habtmAlias])) {
if ($config[$habtmAlias] == false) {
continue;
} else {
$habtmSpecificSettings = $this->_config2settings($config[$habtmAlias]);
}
// Check whether habtm specific settings have been set for this habtm's
// class name (note, you may have 2 assocs using the same class name)
} elseif (isset($config[$habtmAssocData['className']])) {
if ($config[$habtmAssocData['className']] == false) {
continue;
} else {
$habtmSpecificSettings = $this->_config2settings($config[$habtmAssocData['className']]);
}
}
// The behavior needs to know the className, joinTable, foreignKey and
// associationForeignKey of the assoc later, so may as well grab them now.
$habtmSpecificSettings += array_intersect_key($habtmAssocData, array_flip(array('className', 'joinTable', 'foreignKey', 'associationForeignKey')));
// It also needs to know the joinModel, so may as well determine that now
$habtmSpecificSettings['joinModel'] = Inflector::camelize(Inflector::singularize($habtmSpecificSettings['joinTable']));
// Merge any habtm specific settings for the current association with the
// defaults and the config for all associations
$habtmSpecificSettings = array_merge($allHabtmSettings, $habtmSpecificSettings);
// Verify the counterCache and underCounterCache fields specified or
// determined from the defaults actually exist on the habtm model.
$habtmSchema = $model->{$habtmAlias}->schema();
if (!array_key_exists($habtmSpecificSettings['counterCache'], $habtmSchema)) {
$habtmSpecificSettings['counterCache'] = false;
}
if (!array_key_exists('lft', $habtmSchema) || !array_key_exists('rght', $habtmSchema) || !array_key_exists($habtmSpecificSettings['underCounterCache'], $habtmSchema)) {
$habtmSpecificSettings['underCounterCache'] = false;
}
if (!$habtmSpecificSettings['counterCache'] && !$habtmSpecificSettings['underCounterCache']) {
continue;
}
// Store the merged settings in the behavior's settings property indexed
// by the model->alias and the habtmAlias
$this->settings[$model->alias][$habtmAlias] = $habtmSpecificSettings;
}
}
示例14: setup
/**
* Setup the model
*
* @param Model $Model
* @param array $settings
* @return void
* @author David Kullmann
*/
public function setup(Model $Model, $settings = array())
{
parent::setup($Model, $settings);
$Model->findMethods['geo'] = true;
$this->settings[$Model->alias] = Set::merge($this->_defaults, $settings);
}
示例15: setup
/**
* Setup behavior
*/
public function setup(Model $Model, $config = array())
{
parent::setup($Model, $config);
$this->settings[$Model->name] = Hash::merge($this->_defaults, $config);
}