本文整理汇总了PHP中Model::hasField方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::hasField方法的具体用法?PHP Model::hasField怎么用?PHP Model::hasField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::hasField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __prepare
/**
* Return readable fields
*
* @param Model $model Model using this behavior
* @return void
*/
private function __prepare(Model $model)
{
$this->UserAttribute = ClassRegistry::init('UserAttributes.UserAttribute');
$this->UserAttributesRole = ClassRegistry::init('UserRoles.UserAttributesRole');
if (!isset($this->__readableFields)) {
$results = $this->UserAttributesRole->find('list', array('recursive' => -1, 'fields' => array('user_attribute_key', 'user_attribute_key'), 'conditions' => array('role_key' => AuthComponent::user('role_key'), 'other_readable' => true)));
$this->__readableFields = array('id');
foreach ($results as $key => $field) {
//Fieldのチェック
if ($model->hasField($field)) {
$this->__readableFields[$key] = $model->escapeField($field);
}
if ($model->UsersLanguage->hasField($field)) {
$this->__readableFields[$key] = $model->UsersLanguage->escapeField($field);
}
//Field(is_xxxx_public)のチェック
$fieldKey = sprintf(UserAttribute::PUBLIC_FIELD_FORMAT, $field);
if ($model->hasField($fieldKey)) {
$this->__readableFields[$fieldKey] = $model->escapeField($fieldKey);
}
//Field(xxxx_file_id)のチェック
$fieldKey = sprintf(UserAttribute::FILE_FIELD_FORMAT, $field);
if ($model->hasField($fieldKey)) {
$this->__readableFields[$fieldKey] = $model->escapeField($fieldKey);
}
}
}
}
示例2: setup
/**
* Initiate WhoMadeIt Behavior
*
* @param object $model
* @param array $config behavior settings you would like to override
* @return void
* @access public
*/
function setup(Model $model, $config = array())
{
if ($model->alias != 'Dashboard' && $model->alias != 'NotificaionType' && $model->alias != 'Page') {
//assigne default settings
$this->settings[$model->alias] = $this->_defaults;
//merge custom config with default settings
$this->settings[$model->alias] = array_merge($this->settings[$model->alias], (array) $config);
$hasFieldCreatedBy = $model->hasField($this->settings[$model->alias]['created_by_field']);
$hasFieldModifiedBy = $model->hasField($this->settings[$model->alias]['modified_by_field']);
$this->settings[$model->alias]['has_created_by'] = $hasFieldCreatedBy;
$this->settings[$model->alias]['has_modified_by'] = $hasFieldModifiedBy;
//handles model binding to the User model
//according to the auto_bind settings (default true)
if ($this->settings[$model->alias]['auto_bind']) {
if ($hasFieldCreatedBy) {
$commonBelongsTo = array('CreatedBy' => array('className' => $this->settings[$model->alias]['user_model'], 'foreignKey' => $this->settings[$model->alias]['created_by_field'], 'fields' => array('id', 'name')));
$model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
if ($hasFieldModifiedBy) {
$commonBelongsTo = array('ModifiedBy' => array('className' => $this->settings[$model->alias]['user_model'], 'foreignKey' => $this->settings[$model->alias]['modified_by_field'], 'fields' => array('id', 'name')));
$model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
}
}
}
示例3: setup
/**
* Initiate WhoDidIt Behavior
*
* @param object $Model
* @param array $config behavior settings you would like to override
* @return void
* @access public
*/
public function setup(Model $Model, $config = array())
{
//assign default settings
$this->settings[$Model->alias] = $this->_defaults;
//merge custom config with default settings
$this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], (array) $config);
$hasFieldCreatedBy = $Model->hasField($this->settings[$Model->alias]['created_by_field']);
$hasFieldModifiedBy = $Model->hasField($this->settings[$Model->alias]['modified_by_field']);
$hasFieldConfirmedBy = $Model->hasField($this->settings[$Model->alias]['confirmed_by_field']);
$this->settings[$Model->alias]['has_created_by'] = $hasFieldCreatedBy;
$this->settings[$Model->alias]['has_modified_by'] = $hasFieldModifiedBy;
$this->settings[$Model->alias]['has_confirmed_by'] = $hasFieldConfirmedBy;
//handles model binding to the User model
//according to the auto_bind settings (default true)
if ($this->settings[$Model->alias]['auto_bind']) {
if ($hasFieldCreatedBy) {
$commonBelongsTo = array('CreatedBy' => array('className' => $this->settings[$Model->alias]['user_model'], 'foreignKey' => $this->settings[$Model->alias]['created_by_field']));
$Model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
if ($hasFieldModifiedBy) {
$commonBelongsTo = array('ModifiedBy' => array('className' => $this->settings[$Model->alias]['user_model'], 'foreignKey' => $this->settings[$Model->alias]['modified_by_field']));
$Model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
if ($hasFieldConfirmedBy) {
$commonBelongsTo = array('ConfirmedBy' => array('className' => $this->settings[$Model->alias]['user_model'], 'foreignKey' => $this->settings[$Model->alias]['confirmed_by_field']));
$Model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
}
}
示例4: setUp
public function setUp(Model $model, $settings = array())
{
$defaults = array('field' => 'delete_flg', 'field_date' => 'deleted', 'enable' => true);
// Default settings
$this->settings[$model->alias] = Set::merge($defaults, $settings);
$this->settings[$model->alias]['hasField'] = $model->hasField($this->settings[$model->alias]['field']);
$this->settings[$model->alias]['hasFieldDate'] = $model->hasField($this->settings[$model->alias]['field_date']);
}
示例5: beforeSave
/**
* beforeSave callback
*
* @param Model $model The current model being used
* @param array $options Callback options
*
* @return mixed
*/
public function beforeSave(Model $model, $options = array())
{
$fields = (array) $this->__settings[$model->alias]['fields'];
$scope = (array) $this->__settings[$model->alias]['scope'];
$conditions = !empty($this->__settings[$model->alias]['conditions']) ? (array) $this->__settings[$model->alias]['conditions'] : array();
$slugfield = $this->__settings[$model->alias]['slugfield'];
$hasFields = true;
foreach ($fields as $field) {
if (!$model->hasField($field)) {
$hasFields = false;
}
if (!isset($model->data[$model->alias][$field])) {
$hasFields = false;
}
}
if ($hasFields && $model->hasField($slugfield) && ($this->__settings[$model->alias]['overwrite'] || empty($model->id))) {
$toSlug = array();
foreach ($fields as $field) {
$toSlug[] = $model->data[$model->alias][$field];
}
$toSlug = join(' ', $toSlug);
$slug = Inflector::slug($toSlug, $this->__settings[$model->alias]['separator']);
if ($this->__settings[$model->alias]['lower']) {
$slug = strtolower($slug);
}
if (strlen($slug) > $this->__settings[$model->alias]['length']) {
$slug = substr($slug, 0, $this->__settings[$model->alias]['length']);
}
$conditions[$model->alias . '.' . $slugfield . ' LIKE'] = $slug . '%';
if (!empty($model->id)) {
$conditions[$model->alias . '.' . $model->primaryKey . ' !='] = $model->id;
}
if (!empty($scope)) {
foreach ($scope as $s) {
if (isset($model->data[$model->alias][$s])) {
$conditions[$model->alias . '.' . $s] = $model->data[$model->alias][$s];
}
}
}
$sameUrls = $model->find('all', array('recursive' => -1, 'conditions' => $conditions));
$sameUrls = !empty($sameUrls) ? Hash::extract($sameUrls, '{n}.' . $model->alias . '.' . $slugfield) : array();
if (!empty($sameUrls)) {
if (in_array($slug, $sameUrls)) {
$begginingSlug = $slug;
$index = 1;
while ($index > 0) {
if (!in_array($begginingSlug . $this->__settings[$model->alias]['separator'] . $index, $sameUrls)) {
$slug = $begginingSlug . $this->__settings[$model->alias]['separator'] . $index;
$index = -1;
}
$index++;
}
}
}
$model->data[$model->alias][$slugfield] = $slug;
}
return parent::beforeSave($model);
}
示例6: beforeSave
public function beforeSave(Model $model)
{
if (empty($model->id) && $model->hasField('uuid')) {
$model->data[$model->alias]['uuid'] = String::uuid();
}
return true;
}
示例7: setup
/**
* {@inheritdoc}
*/
public function setup(Model $Model, $config = array())
{
if (isset($config[0])) {
$config['fields'] = $config[0];
unset($config[0]);
}
$config = array_merge($this->_defaults, $config);
$config['default'] = reset($config['values']);
if (is_string($config['fields'])) {
$config['fields'] = (array) $config['fields'];
}
foreach ($config['fields'] as $field => $options) {
if (is_numeric($field)) {
unset($config['fields'][$field]);
$field = $options;
$options = $config['fields'][$options] = array();
}
if (!array_key_exists('values', $options)) {
$options = array('values' => empty($options) ? $config['values'] : $options);
}
$config['fields'][$field] = array_merge(array('default' => reset($options['values'])), $options);
if (!$Model->hasField($field) && (!Reveal::is('Sapi.cli') || !in_array('Migrations.migration', env('argv')))) {
$msg = __d('affiliates', "Missing state field '%s' in table '%s'", $field, $Model->useTable);
throw new FatalErrorException($msg);
}
}
$this->settings[$Model->alias] = $config;
}
示例8: setup
public function setup(Model $model, $config = array())
{
$model->medias = array_merge($this->options, $config);
$model->hasMany['Media'] = array('className' => 'Media.Media', 'foreignKey' => 'ref_id', 'order' => 'Media.position ASC', 'conditions' => 'ref = "' . $model->name . '"', 'dependent' => true);
if ($model->hasField('media_id')) {
$model->belongsTo['Thumb'] = array('className' => 'Media.Media', 'foreignKey' => 'media_id', 'conditions' => null, 'counterCache' => false);
}
}
示例9: createSaveDataByToken
/**
* create save data
*
* @param AppModel $model
* @param array $token
* @return array
*/
public function createSaveDataByToken(Model $model, $token)
{
$data = array($model->alias => array($this->settings[$model->alias]['user_id'] => $token['user_id'], $this->settings[$model->alias]['screen_name'] => $token['screen_name'], $this->settings[$model->alias]['oauth_token'] => $token['oauth_token'], $this->settings[$model->alias]['oauth_token_secret'] => $token['oauth_token_secret']));
if ($model->hasField($this->settings[$model->alias]['password'])) {
$data[$model->alias][$this->settings[$model->alias]['password']] = Security::hash($token['oauth_token']);
}
return $data;
}
示例10: hasField
/**
* Ensure that the current model actually has the fields which are configured
* for the status.
*
* @param Model $model
* @return void
*/
protected function hasField(Model $model)
{
foreach ($this->settings[$model->alias]['fields'] as $field) {
if (!$model->hasField($field)) {
trigger_error(__($model->alias . " model doesn't have the field " . $field));
return;
}
}
}
示例11: bindModelBbsArticlesUser
/**
* Set bindModel BbsArticlesUser
*
* @param object $model instance of model
* @param bool $reset Set to false to make the binding permanent
* @return void
*/
public function bindModelBbsArticlesUser(Model $model, $reset)
{
if ($model->hasField('bbs_article_key')) {
$field = 'bbs_article_key';
} else {
$field = 'key';
}
$model->bindModel(array('belongsTo' => array('BbsArticlesUser' => array('className' => 'Bbses.BbsArticlesUser', 'foreignKey' => false, 'conditions' => array('BbsArticlesUser.bbs_article_key = ' . $model->alias . '.' . $field, 'BbsArticlesUser.user_id' => Current::read('User.id'))))), $reset);
}
示例12: load
/**
* Load data files
*
* Options:
* `class` - Class to load. Default to load all classes in directory
* `extract` - Path to identify an entry for `Hash::extract()`
*
* @param string $path Path to directory containing data files
* @param array $options Options array
* @return bool True if loading was successful
* @throws CakeException
*/
public function load($path, $options = array())
{
if (!is_dir($path)) {
throw new CakeException('Argument not a directory: ' . $path);
}
$options = Hash::merge(array('ds' => 'default'), $options);
$dataObjects = App::objects('class', $path);
if (isset($options['class']) && in_array($options['class'], $dataObjects)) {
$dataObjects = array($options['class']);
}
foreach ($dataObjects as $data) {
if (!class_exists($data)) {
include $path . DS . $data . '.php';
}
$classVars = get_class_vars($data);
$modelAlias = substr($data, 0, -4);
$table = $classVars['table'];
$records = $classVars['records'];
$uniqueKeys = null;
if (!empty($options['extract'])) {
$records = Hash::extract($records, $options['extract']);
}
$Model = new Model(array('name' => $modelAlias, 'table' => $table, 'ds' => $options['ds']));
if (!empty($classVars['uniqueFields'])) {
$uniqueKeys = array_flip((array) $classVars['uniqueFields']);
foreach ((array) $classVars['uniqueFields'] as $field) {
if (!$Model->hasField($classVars['uniqueFields'])) {
throw new UnexpectedException("{$field} is not found in table {$table}");
}
}
}
if (is_array($records) && count($records) > 0) {
$i = 0;
foreach ($records as $record) {
if (isset($uniqueKeys)) {
$conditions = array_intersect_key($record, $uniqueKeys);
$count = $Model->find('count', compact('conditions'));
if ($count > 0) {
continue;
}
}
$Model->create($record);
$saved = $Model->save();
if (!$saved) {
CakeLog::error(sprintf('Error loading row #%s for table `%s`', $i + 1, $table));
return false;
}
$i++;
}
$Model->getDatasource()->resetSequence($Model->useTable, $Model->primaryKey);
}
ClassRegistry::removeObject($modelAlias);
}
return true;
}
示例13: beforeValidate
/**
* Before Find
* Transforma o valor de BRL para o formato SQL antes de executar uma query
* com conditions.
*
* @param object $model
* @return boolean
* @access public
*/
public function beforeValidate(Model $model, $config = array())
{
foreach ($model->data[$model->alias] as $field => $value) {
if ($model->hasField($field) && $model->_schema[$field]['type'] == 'float') {
if (!is_string($value) || preg_match('/^[0-9]+(\\.[0-9]+)?$/', $value)) {
continue;
}
$model->data[$model->alias][$field] = str_replace(array('.', ','), array('', '.'), $value);
}
}
return true;
}
示例14: beforeSave
/**
* Set current language
*
* @param Model $Model
* @return void
*/
public function beforeSave(Model $Model, $options = array())
{
if (empty($this->settings[$Model->alias])) {
return;
}
$settings = $this->settings[$Model->alias];
$language = Configure::read('Config.language');
if ($Model->hasField($settings['languageField'])) {
if (empty($Model->data[$Model->alias][$settings['languageField']])) {
$Model->set(array($settings['languageField'] => $language));
}
}
return true;
}
示例15: setup
/**
* Initiate WhoDidIt Behavior.
*
* Checks if the configured fields are available in the model.
* Also binds the User model as association for each available field.
*
* @param Model $Model The model.
* @param array $config Behavior settings you would like to override.
* @return void
*/
public function setup(Model $Model, $config = array())
{
$config += $this->_defaultConfig;
$config['has_created_by'] = $Model->hasField($config['created_by_field']);
$config['has_modified_by'] = $Model->hasField($config['modified_by_field']);
$config['has_confirmed_by'] = $Model->hasField($config['confirmed_by_field']);
// Handles model binding to the User model according to the auto_bind settings (default true).
if ($config['auto_bind']) {
if ($config['has_created_by']) {
$commonBelongsTo = array('CreatedBy' => array('className' => $config['user_model'], 'foreignKey' => $config['created_by_field']));
$Model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
if ($config['has_modified_by']) {
$commonBelongsTo = array('ModifiedBy' => array('className' => $config['user_model'], 'foreignKey' => $config['modified_by_field']));
$Model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
if ($config['has_confirmed_by']) {
$commonBelongsTo = array('ConfirmedBy' => array('className' => $config['user_model'], 'foreignKey' => $config['confirmed_by_field']));
$Model->bindModel(array('belongsTo' => $commonBelongsTo), false);
}
}
$this->settings[$Model->alias] = $config;
}