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


PHP AppModel::create方法代码示例

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


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

示例1: create

 /**
  * Creates a new ARO/ACO node
  *
  * @param int $linkId
  * @param mixed $parentId
  * @param string $alias
  * @return boolean True on success, false on fail
  * @access public
  */
 function create($linkId = 0, $parentId = null, $alias = '')
 {
     parent::create();
     if (strtolower(get_class($this)) == "aclnode") {
         trigger_error("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration.", E_USER_ERROR);
         return null;
     }
     extract($this->__dataVars());
     if ($parentId == null || $parentId === 0) {
         $parent = $this->find(null, 'MAX(rght) as rght', null, -1);
         $parent['lft'] = $parent[0]['rght'];
         if ($parent[0]['rght'] == null || !$parent[0]['rght']) {
             $parent['lft'] = 0;
         }
     } else {
         $parent = $this->find($this->_resolveID($parentId), null, null, 0);
         if ($parent == null || count($parent) == 0) {
             trigger_error("Null parent in {$class}::create()", E_USER_WARNING);
             return null;
         }
         $parent = $parent[$class];
         $this->_syncTable(1, $parent['lft'], $parent['lft']);
     }
     $return = $this->save(array($class => array($secondary_id => $linkId, 'alias' => $alias, 'lft' => $parent['lft'] + 1, 'rght' => $parent['lft'] + 2)));
     $this->id = $this->getLastInsertID();
     return $return;
 }
开发者ID:venka10,项目名称:RUS,代码行数:36,代码来源:aclnode.php

示例2: create

 function create($data = array(), $filterKey = false)
 {
     parent::create($data, $filterKey);
     if (empty($this->data[$this->name]['activity_id'])) {
         $default_activity = $this->Activity->default_value('ACTI');
         if (!empty($default_activity)) {
             $this->set('activity_id', $default_activity['Activity']['id']);
         }
     }
     return $this->data;
 }
开发者ID:gildonei,项目名称:candycane,代码行数:11,代码来源:TimeEntry.php

示例3: sess_write

function sess_write($key, $value)
{
    // If the client doesn't have a session, and one isn't being created ($value), do nothing.
    if (empty($_COOKIE[session_name()]) && empty($value)) {
        return TRUE;
    }
    $Controller = getInstance()->Controller;
    $Session = new AppModel('Session');
    $result = $Session->findById($key);
    $user_id = 0;
    if (isset($Controller->User->user['id'])) {
        $user_id = $Controller->User->user['id'];
    }
    if (isset($result['Session']['id'])) {
        $Session->save(array('hostname' => $_SERVER['REMOTE_ADDR'], 'session' => $value), array('id' => $key));
    } else {
        $Session->create(array('id' => $key, 'hostname' => $_SERVER['REMOTE_ADDR'], 'session' => $value));
    }
    return TRUE;
}
开发者ID:nowk,项目名称:baseapp-framework,代码行数:20,代码来源:session_helper.php

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

示例5: 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.
  *
  * @since 1.2
  * @TODO Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB.
  * @param AppModel $model
  * @param string $mode parent or tree
  * @return boolean True on success, false on failure
  * @access public
  */
 function recover(&$model, $mode = 'parent')
 {
     extract($this->settings[$model->name]);
     $model->recursive = -1;
     if ($mode == 'parent') {
         $count = 1;
         foreach ($model->findAll($scope, array($model->primaryKey)) as $Array) {
             $model->{$model->primaryKey} = $Array[$model->name][$model->primaryKey];
             $lft = $count++;
             $rght = $count++;
             $model->save(array($left => $lft, $right => $rght));
         }
         foreach ($model->findAll($scope, array($model->primaryKey, $parent)) as $Array) {
             $model->create();
             $model->id = $Array[$model->name][$model->primaryKey];
             $this->_set_parent($model, $Array[$model->name][$parent], true);
         }
     } else {
         foreach ($model->findAll($scope, array($model->primaryKey, $parent)) as $Array) {
             $path = $this->get_path($model, $Array[$model->name][$model->primaryKey]);
             if ($path == null || count($path) < 2) {
                 $parent_id = null;
             } else {
                 $parent_id = $path[count($path) - 2][$model->name][$model->primaryKey];
             }
             // Sidestep beforeSave
             $model->updateAll(array($parent => $parent_id), array($model->primaryKey => $Array[$model->name][$model->primaryKey]));
         }
     }
 }
开发者ID:paulToro,项目名称:webrocket,代码行数:44,代码来源:tree.php

示例6: 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.
  *
  * @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB.
  * @param AppModel $model
  * @param string $mode parent or tree
  * @return boolean true on success, false on failure
  * @access public
  */
 function recover(&$model, $mode = 'parent')
 {
     extract($this->settings[$model->alias]);
     $model->recursive = -1;
     if ($mode == 'parent') {
         $count = 1;
         foreach ($model->find('all', array('conditions' => $scope, 'fields' => array($model->primaryKey), 'order' => $left)) as $array) {
             $model->{$model->primaryKey} = $array[$model->alias][$model->primaryKey];
             $lft = $count++;
             $rght = $count++;
             $model->save(array($left => $lft, $right => $rght));
         }
         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], true);
         }
     } else {
         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 => $parentId), array($model->escapeField() => $array[$model->alias][$model->primaryKey]));
         }
     }
 }
开发者ID:kaz0636,项目名称:openflp,代码行数:42,代码来源:tree.php

示例7: 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.
  *
  * @param AppModel $model
  * @param array $conditions
  * @param int $recursive
  * @return bool true on success false otherwise
  * @access public
  */
 function resetSlugs(&$model, $conditions = array(), $recursive = -1)
 {
     extract($this->settings[$model->alias]);
     if (!$model->hasField($slugField)) {
         return false;
     }
     $fields = array_merge((array) $model->primaryKey, $label);
     $sort = $model->displayField . ' ASC';
     $count = $model->find('count');
     set_time_limit(max(30, $count / 100));
     foreach ($model->find('all', compact('conditions', 'fields', 'sort', 'recursive')) as $row) {
         $model->create();
         $model->save($row);
     }
     return true;
 }
开发者ID:hiromi2424,项目名称:cookbook,代码行数:28,代码来源:slugged.php

示例8: admin_add

 public function admin_add()
 {
     if ($this->data != null) {
         // create
         $this->Model = AppModel::create(Url::$data['modelName'], $this->data);
         // save & redirect?
         if ($this->Model->save()) {
             $this->redirect(DS . ADMIN_ROUTE . DS . Url::$data['controller'], false);
         }
     } else {
         // pre-data?
         $pre_data = $this->filter->field ? array($this->filter->field => $this->filter->value) : null;
         // create empty
         $this->Model = AppModel::create(Url::$data['modelName'], $pre_data);
     }
     $this->assign('item', $this->Model);
 }
开发者ID:nemoDreamer,项目名称:endo,代码行数:17,代码来源:controller.endo.php

示例9: createLog

 public function createLog($userid, $entity, $action, $incident, $entidade_id)
 {
     parent::create(array('usuario_id' => $userid, 'tx_entidade' => $entity, 'tx_evento' => $action, 'tx_ocorrencia' => $incident, 'entidade_id' => $entidade_id));
     parent::save();
 }
开发者ID:alextalha,项目名称:sg,代码行数:5,代码来源:Logevento.php

示例10: __insertAtPosition

 /**
  * Inserts an item on a certain position
  *
  * @param AppModel $model
  * @param $position
  * @return boolean
  */
 private function __insertAtPosition($model, $position)
 {
     extract($this->settings[$model->alias]);
     $data = $model->data;
     $model->data[$model->alias][$positionColumn] = 0;
     $model->save(null, array('validate' => $validate, 'callbacks' => $callbacks));
     $model->create($data);
     $model->recursive = 0;
     $model->findById($model->id);
     $this->removeFromList($model);
     $result = $this->__incrementPositionsOnLowerItems($model, $position);
     if ($position <= $this->__bottomPositionInList($model) + 1) {
         $model->data[$model->alias][$positionColumn] = $position;
         $result = $model->save(null, array('validate' => $validate, 'callbacks' => $callbacks));
     }
     return $result;
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:24,代码来源:ListBehavior.php

示例11: 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.
  *
  * @param AppModel $Model
  * @param array $conditions
  * @param int $recursive
  * @return bool true on success false otherwise
  * @access public
  */
 public function resetSlugs(&$Model, $params = array())
 {
     $recursive = -1;
     extract($this->settings[$Model->alias]);
     if ($notices && !$Model->hasField($slugField)) {
         return false;
     }
     $defaults = array('page' => 1, 'limit' => 100, 'fields' => array_merge(array($Model->primaryKey, $slugField), $label), 'order' => $Model->displayField . ' ASC', 'conditions' => array(), 'recursive' => $recursive);
     $params = array_merge($defaults, $params);
     $count = $Model->find('count', compact('conditions'));
     $max = ini_get('max_execution_time');
     if ($max) {
         set_time_limit(max($max, $count / 100));
     }
     while ($rows = $Model->find('all', $params)) {
         foreach ($rows as $row) {
             $Model->create();
             $Model->save($row, true, array($slugField));
         }
         $params['page']++;
     }
     return true;
 }
开发者ID:razzman,项目名称:mi,代码行数:35,代码来源:SluggedBehavior.php

示例12: __doTreeSave

 /**
  *
  * Private function that saves the nodes recursively 
  * 
  * @param AppModel $Model Model instance
  * @param array $data The nodes to create
  * @param array $options Settings
  * @return mixed true if succesfully saved or false on error
  * @access private
  */
 private function __doTreeSave($Model, $data, $options = array())
 {
     $return = false;
     //Special case in the first run
     if ($options['depth'] > 0) {
         $Model->create();
         if (!$Model->save(array_diff_key(array_merge(array($this->settings[$Model->alias]['scopeField'] => $options['scope'], $this->settings[$Model->alias]['parent'] => $options['parent']), $data), array($Model->alias => $Model->alias)))) {
             return false;
         }
         $options['parent'] = $Model->getInsertID();
         $return = true;
     }
     if (array_key_exists($Model->alias, $data)) {
         $options['depth']++;
         foreach ($data[$Model->alias] as $childData) {
             if (!$this->__doTreeSave($Model, $childData, $options)) {
                 return false;
             }
         }
         $return = true;
     }
     return $return;
 }
开发者ID:nani8124,项目名称:infinitas,代码行数:33,代码来源:InfiniTreeBehavior.php

示例13: foreach

 /**
  * Updates the counter caches of each node in the parentIds property. Called
  * after save or after deletion of a node.
  *
  * @param AppModel $model The model object that the behavior is attached to
  * @access protected
  */
 function _updateCounterCache(&$model)
 {
     // Foreach item in the parentIds property array...
     foreach ($this->_parentIds[$model->alias] as $k => $parentId) {
         // Reset the $model
         $model->create();
         // Initialise the data array for saving
         $data = array($model->alias => array($model->primaryKey => $parentId));
         // Set the child count of the current node
         if ($this->settings[$model->alias]['child_count']) {
             $data[$model->alias][$this->settings[$model->alias]['child_count']] = $model->childCount($parentId);
         }
         // Set the direct child count of the current node
         if ($this->settings[$model->alias]['direct_child_count']) {
             $data[$model->alias][$this->settings[$model->alias]['direct_child_count']] = $model->childCount($parentId, true);
         }
         // Save the data with new counter caches
         $model->save($data, array('validate' => false, 'callbacks' => false));
         unset($this->_parentIds[$model->alias][$k]);
     }
 }
开发者ID:neilcrookes,项目名称:tree_counter_cache,代码行数:28,代码来源:tree_counter_cache.php


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