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


PHP AppModel::bindModel方法代码示例

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


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

示例1: setup

 /**
  * Setup
  *
  * @param AppModel $model
  * @param array $settings
  * @access public
  */
 public function setup(&$model, $settings = array())
 {
     if (!isset($this->settings[$model->alias])) {
         $this->settings[$model->alias] = $this->defaults;
     }
     $this->settings[$model->alias] = am($this->settings[$model->alias], ife(is_array($settings), $settings, array()));
     $cfg = $this->settings[$model->alias];
     $model->bindModel(array('hasMany' => array('Comment' => array('className' => $cfg['commentModel'], 'foreignKey' => 'foreign_key', 'unique' => true, 'conditions' => '', 'fields' => '', 'dependent' => true, 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => ''))), false);
     $model->Comment->bindModel(array('belongsTo' => array($model->name => array('className' => $model->name, 'foreignKey' => 'foreign_key', 'unique' => true, 'conditions' => '', 'fields' => '', 'dependent' => false))), false);
     $model->Comment->bindModel(array('belongsTo' => array($cfg['userModelAlias'] => array('className' => $cfg['userModelClass'], 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => '', 'counterCache' => true, 'order' => ''))), false);
 }
开发者ID:hiltongoncalves,项目名称:Comments,代码行数:18,代码来源:commentable.php

示例2: recover

 /**
  * Recover a corrupted tree
  *
  * The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data
  * will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode
  * 'parent' the values of the parent_id field will be used to populate the left and right fields. The missingParentAction
  * parameter only applies to "parent" mode and determines what to do if the parent field contains an id that is not present.
  *
  * @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB.
  * @param AppModel $Model Model instance
  * @param string $mode parent or tree
  * @param mixed $missingParentAction 'return' to do nothing and return, 'delete' to
  * delete, or the id of the parent to set as the parent_id
  * @return boolean true on success, false on failure
  * @access public
  * @link http://book.cakephp.org/view/1628/Recover
  */
 function recover(&$Model, $mode = 'parent', $missingParentAction = null)
 {
     if (is_array($mode)) {
         extract(array_merge(array('mode' => 'parent'), $mode));
     }
     extract($this->settings[$Model->alias]);
     $Model->recursive = $recursive;
     if ($mode == 'parent') {
         $Model->bindModel(array('belongsTo' => array('VerifyParent' => array('className' => $Model->alias, 'foreignKey' => $parent, 'fields' => array($Model->primaryKey, $left, $right, $parent)))));
         $missingParents = $Model->find('list', array('recursive' => 0, 'conditions' => array($scope, array('NOT' => array($Model->escapeField($parent) => null), $Model->VerifyParent->escapeField() => null))));
         $Model->unbindModel(array('belongsTo' => array('VerifyParent')));
         if ($missingParents) {
             if ($missingParentAction == 'return') {
                 foreach ($missingParents as $id => $display) {
                     $this->errors[] = 'cannot find the parent for ' . $Model->alias . ' with id ' . $id . '(' . $display . ')';
                 }
                 return false;
             } elseif ($missingParentAction == 'delete') {
                 $Model->deleteAll(array($Model->primaryKey => array_flip($missingParents)));
             } else {
                 $Model->updateAll(array($parent => $missingParentAction), array($Model->escapeField($Model->primaryKey) => array_flip($missingParents)));
             }
         }
         $count = 1;
         foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey), 'order' => $left)) as $array) {
             $Model->id = $array[$Model->alias][$Model->primaryKey];
             $lft = $count++;
             $rght = $count++;
             $Model->save(array($left => $lft, $right => $rght), array('callbacks' => false));
         }
         foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
             $Model->create();
             $Model->id = $array[$Model->alias][$Model->primaryKey];
             $this->_setParent($Model, $array[$Model->alias][$parent]);
         }
     } else {
         $db =& ConnectionManager::getDataSource($Model->useDbConfig);
         foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
             $path = $this->getpath($Model, $array[$Model->alias][$Model->primaryKey]);
             if ($path == null || count($path) < 2) {
                 $parentId = null;
             } else {
                 $parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey];
             }
             $Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey]));
         }
     }
     return true;
 }
开发者ID:ale3andro,项目名称:metathesi,代码行数:66,代码来源:tree.php

示例3: to_40

 /**
  * Upgrade to 4.0.0.
  */
 public function to_40()
 {
     $answer = strtoupper($this->in('This upgrade will delete the following tables after migration: settings, access, access_levels. Are you sure you want to continue?', array('Y', 'N')));
     if ($answer === 'N') {
         exit;
     }
     $Access = new AppModel(null, 'access', FORUM_DATABASE);
     $Access->alias = 'Access';
     $Access->tablePrefix = FORUM_PREFIX;
     $Access->bindModel(array('belongsTo' => array('User' => array('className' => FORUM_USER))));
     $AccessLevel = new AppModel(null, 'access_levels', FORUM_DATABASE);
     $AccessLevel->alias = 'AccessLevel';
     $AccessLevel->tablePrefix = FORUM_PREFIX;
     $Forum = ClassRegistry::init('Forum.Forum');
     $Acl = ClassRegistry::init('Forum.Access');
     // Create ACL request objects
     $this->out('Installing ACL...');
     $aclMap = $Acl->installAcl();
     $levelMap = array();
     foreach ($AccessLevel->find('all') as $level) {
         $id = $level['AccessLevel']['id'];
         if ($id == 3) {
             $alias = Configure::read('Forum.aroMap.superMod');
         } else {
             if ($id == 4) {
                 $alias = Configure::read('Forum.aroMap.admin');
             } else {
                 continue;
             }
         }
         $record = $Acl->getBySlug($alias);
         $levelMap[$id] = $record['Access']['id'];
     }
     // Create users
     $this->out('Migrating users...');
     foreach ($Access->find('all') as $user) {
         $Acl->add(array('foreign_key' => $user['User']['id'], 'parent_id' => $levelMap[$user['Access']['access_level_id']]));
     }
     // Migrate access levels
     $this->out('Migrating access relations...');
     $forums = $Forum->find('all', array('conditions' => array('Forum.access_level_id !=' => 0)));
     if ($forums) {
         foreach ($forums as $forum) {
             $Forum->id = $forum['Forum']['id'];
             $Forum->save(array('access_level_id' => $levelMap[$forum['Forum']['access_level_id']]), false);
         }
     }
     // Delete tables
     $this->out('Deleting old tables...');
     return $this->_querySql('4.0');
 }
开发者ID:alescx,项目名称:forum,代码行数:54,代码来源:UpgradeShell.php


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