menu_save_item
modules/menu/menu.module, строка 559
- Версии
- 5
menu_save_item(&$item)
Save a menu item to the database.
Параметры
$item
The menu item to be saved. This is passed by reference, so that the newly
generated $item['mid']
can be accessed after an insert takes place.
Возвращаемое значение
$status
The operation that was performed in saving. Either SAVED_NEW (if a new
menu item was created), or SAVED_UPDATED (if an existing menu item was
updated).
Код
<?php
function menu_save_item(&$item) {
$existing_item = NULL;
// Check that the item already exists in the menu tree, if $item['mid'] is
// specified.
if (isset($item['mid'])) {
$existing_item = menu_get_item($item['mid']);
}
if ($item['mid'] && !empty($existing_item)) {
db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', description = '%s', weight = %d, type = %d WHERE mid = %d", $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type'], $item['mid']);
return SAVED_UPDATED;
}
else {
$item['mid'] = db_next_id('{menu}_mid');
// Check explicitly for mid <= 2. If the database was improperly prefixed,
// this would cause a nasty infinite loop or duplicate mid errors.
// TODO: have automatic prefixing through an installer to prevent this.
while ($item['mid'] <= 2) {
$item['mid'] = db_next_id('{menu}_mid');
}
db_query("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)", $item['mid'], $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type']);
return SAVED_NEW;
}
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии