本文整理汇总了PHP中AppModel::getInsertID方法的典型用法代码示例。如果您正苦于以下问题:PHP AppModel::getInsertID方法的具体用法?PHP AppModel::getInsertID怎么用?PHP AppModel::getInsertID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppModel
的用法示例。
在下文中一共展示了AppModel::getInsertID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: refrect
/**
* 関連ページに反映する
*
* @param string $type
* @param array $data
* @return boolean
*/
public function refrect($type, $data)
{
if (isset($this->data['Page'])) {
$data = $this->data['Page'];
}
// モバイルページへのコピーでスーパークラスのIDを上書きしてしまうので退避させておく
$this->__pageInsertID = parent::getInsertID();
$agentId = $this->PageCategory->getAgentId($type);
if (!$agentId) {
// カテゴリがない場合は trueを返して終了
return true;
}
$data['url'] = '/' . Configure::read('BcAgent.' . $type . '.prefix') . $this->removeAgentPrefixFromUrl($data['url']);
$agentPage = $this->find('first', array('conditions' => array('Page.url' => $data['url']), 'recursive' => -1));
unset($data['id']);
unset($data['sort']);
unset($data['status']);
if ($agentPage) {
$agentPage['Page']['name'] = $data['name'];
$agentPage['Page']['title'] = $data['title'];
$agentPage['Page']['description'] = $data['description'];
$agentPage['Page']['draft'] = $data['draft'];
$agentPage['Page']['modified'] = $data['modified'];
$agentPage['Page']['contents'] = $data['contents'];
$agentPage['Page']['reflect_mobile'] = false;
$agentPage['Page']['reflect_smartphone'] = false;
$this->set($agentPage);
} else {
if ($data['page_category_id']) {
$fields = array('parent_id', 'name', 'title');
$pageCategoryTree = $this->PageCategory->getTreeList($fields, $data['page_category_id']);
$path = getViewPath() . 'Pages' . DS . Configure::read('BcAgent.' . $type . '.prefix');
$parentId = $agentId;
foreach ($pageCategoryTree as $pageCategory) {
$path .= '/' . $pageCategory['PageCategory']['name'];
$categoryId = $this->PageCategory->getIdByPath($path);
if (!$categoryId) {
$pageCategory['PageCategory']['parent_id'] = $parentId;
$this->PageCategory->create($pageCategory);
$ret = $this->PageCategory->save();
$parentId = $categoryId = $this->PageCategory->getInsertID();
} else {
$parentId = $categoryId;
}
}
$data['page_category_id'] = $categoryId;
} else {
$data['page_category_id'] = $agentId;
}
$data['author_id'] = $_SESSION['Auth']['User']['id'];
$data['sort'] = $this->getMax('sort') + 1;
$data['status'] = false;
// 新規ページの場合は非公開とする
unset($data['publish_begin']);
unset($data['publish_end']);
unset($data['created']);
unset($data['modified']);
$data['reflect_mobile'] = false;
$data['reflect_smartphone'] = false;
$this->create($data);
}
return $this->save();
}
示例2: setSearchableRecords
/**
* Creates array of $model->alias => array($model->id => $model->data) for
* use by afterDelete or afterSave.
*
* @param AppModel $model
* @param boolean $created Indicates whether the record is being/was created
* @param boolean $reset Determines whether to reset the _records property
* before adding new ones.
*/
function setSearchableRecords(&$model, $created = false, $reset = false)
{
if ($reset) {
$this->_records = array();
}
// Set the foreign key from either the model id or the last inserted id
$foreignKey = $model->id;
if (!$foreignKey && $created) {
$foreignKey = $model->getInsertID();
}
$this->_records[$model->alias][$foreignKey] = $model->data;
}
示例3: conditionsNotCurrent
/**
* When doing any update all calls, you want to avoid updating the record
* you've just modified, as the order will have been set already, so exclude
* it with some conditions.
*
* @param AppModel $model
* @return array Array Model.primary_key => $id
*/
function conditionsNotCurrent(&$model)
{
if (!($id = $model->id)) {
$id = $model->getInsertID();
}
return array($model->escapeField($model->primaryKey) . ' <>' => $id);
}
示例4: getInsertID
/**
* 最終登録IDを取得する
*
* @return int
*/
public function getInsertID()
{
if (!$this->__pageInsertID) {
$this->__pageInsertID = parent::getInsertID();
}
return $this->__pageInsertID;
}
示例5: __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;
}