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


PHP AppModel::schema方法代码示例

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


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

示例1: valueList

 /**
  * get valuelist from filemaker layout
  * 
  * @param AppModel $model
  * @param string $fieldName
  * @return mixed array or false
  */
 function valueList(&$model, $fieldName = null)
 {
     if (empty($model->returnValueLists) || !$model->returnValueLists) {
         return false;
     }
     if ($fields = $model->schema()) {
         $valueList = array();
         foreach ($fields as $_fieldName => $_schema) {
             if (!empty($_schema['valuelist'])) {
                 $valueList[$_fieldName] = array();
                 foreach ($_schema['valuelist'] as $value) {
                     $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
                     $valueList[$_fieldName][$value] = $value;
                 }
             }
         }
         if (empty($fieldName)) {
             return $valueList;
         } else {
             if (!empty($valueList[$fieldName])) {
                 return $valueList[$fieldName];
             }
         }
     }
     return false;
 }
开发者ID:nojimage,项目名称:FileMaker-Todo-App,代码行数:33,代码来源:fm_value_list.php

示例2: _checkSchema

 /**
  * Check DB table for localized fields and define them if needed
  *
  * @param AppModel $model
  * @return bool (true if no changes were made)
  */
 protected function _checkSchema($model)
 {
     if (empty($this->_ready[$model->alias])) {
         $this->_ready[$model->alias] = true;
     } else {
         return;
     }
     $fields = $this->settings[$model->alias];
     if (empty($fields)) {
         return true;
     }
     $locales = SlConfigure::read('I18n.locales');
     if (empty($locales)) {
         trigger_error('I18n didn\'t initilialize properly.', E_USER_ERROR);
         return false;
     }
     $db =& ConnectionManager::getDataSource($model->useDbConfig);
     $schema = $model->schema();
     $alterTable = array();
     // add all localized missing fields in this model
     foreach ($fields as $field) {
         foreach ($locales as $locale) {
             $field_lang = $field . '_' . $locale;
             if (empty($schema[$field_lang])) {
                 if (empty($schema[$field])) {
                     trigger_error("Table for {$model->alias} Model doesn't have a field named '{$field}'!", E_USER_ERROR);
                 }
                 $alterTable[$model->table]['add'][$field_lang] = $schema[$field];
             }
         }
     }
     foreach ($locales as $locale) {
         $field_lang = '_' . $locale;
         if (empty($schema[$field_lang])) {
             $alterTable[$model->table]['add'][$field_lang] = array('type' => 'boolean', 'null' => false);
         }
     }
     if ($alterTable) {
         if (!method_exists($db, 'alterSchema')) {
             trigger_error("Table configuration for {$model->alias} Model could not be changed to reflect your latest language settings because its DataSource does not support altering schemas.", E_USER_ERROR);
         }
         $model->cacheSources = false;
         $model->cacheQueries = false;
         // delete cached model file
         clearCache("{$model->useDbConfig}_{$model->table}", 'models', '');
         // execute alter table and update schema
         $model->query($db->alterSchema($alterTable));
         $model->schema(true);
         // output a notice about updated DB table
         trigger_error("Table configuration for {$model->alias} Model has changed to reflect your latest language settings.", E_USER_NOTICE);
         return false;
     }
     return true;
 }
开发者ID:sandulungu,项目名称:StarLight,代码行数:60,代码来源:translate.php

示例3: setup

 /**
  * Initiate SearchableBehavior
  *
  * @param AppModel $model
  * @param array $config Array of options for configuring the Searchable
  * Behavior settings for the given model. Keys include:
  * - fields - array of fields from the model to include in the search index.
  * If omitted, all char, varchar, string, text fields will be included.
  * To include data from fields in the current model, just specify the field
  * name. E.g. array('title')
  * The Searchable Behavior can include data from associated models in the
  * Search Index too. This is useful for say Post belongsTo Category, and you
  * want the Category name included in the Search Index.
  * To achieve this, specify the field name in the current model as the key and
  * the model and field in the associated model as the value. E.g.
  * array('category_id' => 'Category.name')
  * - scope - array of conditions in the form array('field' => 'value') to
  * apply to determine whether the record in the Search Index is active or not,
  * and therefore whether it should be included in the search results. If
  * omitted, the record in the Search Index is always active.
  * - name - the field to be used from the Searchable model when populating the
  * name field in the Search Index. This is used as the title of a search
  * result entry on the results page, and has the link to view the result on
  * it. If omitted, the displayField of the model is used. Set to false if you
  * don't want the title field to be populated.
  * - summary - the field to be used from the Searchable model when populating
  * the summary field in the Search Index. This is used as the summary of a
  * search result entry on the results page. If omitted, no field is used, and
  * the summary will be a series of excerpts from the Search Index data with
  * the search terms highlighted.
  * - published - the field to be used from the Searchable model when
  * populating the published field in the Search Index. This can be used in the
  * conditions array when performing the search. If omitted, no field is used,
  * and the published field contain NULL.
  * - url - array of url elements e.g. controller, action etc. If controller is
  * omitted, the controller version of the model is used. If action is omitted,
  * view is used, if there are no other non-url paramters (e.g. slug), the
  * Searchable Model primary key value is added to the url.
  */
 function setup(&$model, $config = array())
 {
     if (!is_array($config)) {
         $config = array($config);
     }
     // Add config to settings for given model
     $this->settings[$model->alias] = array_merge($this->_defaults, $config);
     // Normalize the fields property using default string types from the model
     // schema if not specified, or processing the fields config param passed in.
     if (empty($this->settings[$model->alias]['fields'])) {
         foreach ($model->schema() as $field => $info) {
             if (in_array($info['type'], array('text', 'varchar', 'char', 'string', 'date'))) {
                 $this->settings[$model->alias]['fields'][$model->alias . '.' . $field] = $model->alias . '.' . $field;
             }
         }
     } else {
         // Ensure fields is in the format array(Model.field => Model.field, ...)
         foreach ($this->settings[$model->alias]['fields'] as $field => $modelField) {
             unset($this->settings[$model->alias]['fields'][$field]);
             if (strpos($modelField, '.') === false) {
                 $modelField = $model->alias . '.' . $modelField;
             }
             if (is_numeric($field)) {
                 $field = $modelField;
             } elseif (strpos($field, '.') === false) {
                 $field = $model->alias . '.' . $field;
             }
             $this->settings[$model->alias]['fields'][$field] = $modelField;
         }
     }
     // Set 'name' to false if you don't want to populate the 'name' field
     if (!isset($this->settings[$model->alias]['name']) || $this->settings[$model->alias]['name'] !== false) {
         $this->settings[$model->alias]['name'] = $model->displayField;
     }
     // If url is not an array, make it one
     if (!isset($this->settings[$model->alias]['url'])) {
         $this->settings[$model->alias]['url'] = array();
     }
     // Add default plugin url component of null
     if (!isset($this->settings[$model->alias]['url']['plugin'])) {
         $this->settings[$model->alias]['url']['plugin'] = null;
     }
     // Add default controller url component of controller version of model
     if (!isset($this->settings[$model->alias]['url']['controller'])) {
         $this->settings[$model->alias]['url']['controller'] = Inflector::pluralize(Inflector::underscore($model->alias));
     }
     // Add default action of view
     if (!isset($this->settings[$model->alias]['url']['action'])) {
         $this->settings[$model->alias]['url']['action'] = 'view';
     }
 }
开发者ID:TehTreag,项目名称:cakepackages,代码行数:90,代码来源:searchable.php

示例4: schema

 /**
  * Dynamically set the schema to the properties the corresponding data source is expecting
  * when using the elastic search data source it will return the elastic mapping
  *
  * @param mixed $field (optional)
  * @return array
  */
 public function schema($field = false)
 {
     if ($this->isElastic()) {
         if (!empty($this->_schema) && !isset($this->_oldSchema)) {
             $this->_oldSchema = $this->_schema;
         }
         $schema = $this->_schema = $this->elasticMapping();
         if ($field && is_string($field)) {
             return Hash::get($schema, $field);
         }
         return $schema;
     }
     if (!empty($this->_oldSchema)) {
         $this->_schema = $this->_oldSchema;
         unset($this->_oldSchema);
     }
     // Failsafe to prevent schema mix-ups
     if (method_exists($this, 'elasticMapping') && $this->_schema === $this->elasticMapping()) {
         $this->_schema = null;
     }
     return parent::schema($field);
 }
开发者ID:el-barto,项目名称:cakephp-elastic-search-datasource,代码行数:29,代码来源:ElasticAppModel.php

示例5: copyLanguage

 private function copyLanguage($object, $id, $newId)
 {
     if (isset($object->multiLanguage['columns'])) {
         $tableLanguage = 'multilanguage_' . $object->useTable;
         $model = new AppModel();
         $model->useTable = $tableLanguage;
         $fields = array_keys($model->schema());
         $fieldSelect = $fieldInsert = array();
         foreach ($fields as $field) {
             if (in_array($field, array('id'))) {
                 continue;
             }
             $fieldInsert[] = '`' . $field . '`';
             if ($field == 'object_id') {
                 $fieldSelect[] = '"' . $newId . '"';
             } else {
                 $fieldSelect[] = '`' . $field . '`';
             }
         }
         $query = 'INSERT INTO ' . $model->useTable . ' (' . implode(',', $fieldInsert) . ') SELECT ' . implode(',', $fieldSelect) . ' FROM ' . $model->useTable . ' WHERE object_id = ' . $id;
         $this->query($query);
     }
 }
开发者ID:pdkhuong,项目名称:BBG,代码行数:23,代码来源:AppModel.php

示例6: bakeModel

 function bakeModel($model)
 {
     if (App::import('Model', $model)) {
         $object = new $model();
     } else {
         App::import('Model', 'App');
         $object = new AppModel(array('name' => $model));
     }
     $fields = $object->schema();
     $out = "/* SVN FILE: \$Id\$ */\n";
     $out .= "package " . $this->paths['model'] . "\n{\n";
     $out .= "\timport com.fake.model.Model\n\n";
     $out .= "\tpublic class " . $model . " extends Model\n";
     $out .= "\t{\n";
     if (!empty($fields)) {
         foreach ($fields as $field => $options) {
             $out .= "\t\tpublic var " . $field . ":" . $this->__type($options['type']) . ";\n";
         }
     }
     $out .= "\n\t\tpublic function " . $model . "()\n";
     $out .= "\t\t{\n\n\t\t}\n";
     $out .= "\t}\n";
     $out .= "}\n";
     $path = rtrim($this->params['src'], DS) . DS . join(DS, explode('.', $this->paths['model'])) . DS . $model . '.as';
     return $this->createFile($path, $out);
 }
开发者ID:BGCX067,项目名称:fake-as3-svn-to-git,代码行数:26,代码来源:fake.php


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