本文整理汇总了PHP中Category_Model::edit方法的典型用法代码示例。如果您正苦于以下问题:PHP Category_Model::edit方法的具体用法?PHP Category_Model::edit怎么用?PHP Category_Model::edit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category_Model
的用法示例。
在下文中一共展示了Category_Model::edit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
/**
* Редактирует категорию
* @param $args array mixed
* @return void
*/
function edit(array $args = array())
{
$errors = array();
$categorys = Core::getInstance()->user->getUserCategory();
$category = null;
if (array_key_exists(0, $args) && array_key_exists($args[0], $categorys)) {
$category = array('id' => (int) $args[0], 'name' => $categorys[$args[0]]['cat_name'], 'parent' => $categorys[$args[0]]['cat_parent'], 'system' => $categorys[$args[0]]['system_category_id'], 'type' => $categorys[$args[0]]['type']);
}
if ($this->request->method == 'POST') {
$category = array('id' => isset($this->request->post['id']) ? $this->request->post['id'] : $category['id'], 'name' => $this->request->post['name'], 'parent' => (int) $this->request->post['parent'], 'system' => (int) $this->request->post['system'], 'type' => (int) $this->request->post['type']);
if (!strlen($category['name'])) {
$errors[] = 'Название не может быть пустым!';
}
if (!$category['parent'] && !$category['system']) {
$errors[] = 'Вы должны указать системную или родительскую категорию.';
}
if (!sizeof($errors)) {
$this->model->edit($category['id'], $category['name'], $category['parent'], $category['system'], $category['type']);
$this->tpl->assign('result', array('text' => "Категория успешно изменена."));
} else {
$this->tpl->assign('error', array('text' => implode(" \n", $errors)));
}
}
$this->tpl->assign('category', $category);
$this->tpl->assign('name_page', 'category/edit');
}
示例2: update
/**
* 更新联系人分组名
* @param int $id 分组ID
*/
public function update($id = NULL)
{
if ($this->get_method() != 'POST') {
$this->send_response(405, NULL, Kohana::lang('contact.method_not_exist'));
}
$data = $this->get_data();
$name = isset($data['name']) ? $data['name'] : '';
$id = (int) $id;
if (empty($id)) {
$this->send_response(400, NULL, Kohana::lang('contact.group_id_empty'));
} elseif (empty($name)) {
$this->send_response(400, NULL, Kohana::lang('contact.group_name_empty'));
} elseif (mb_strlen($name, 'utf8') > 32) {
$this->send_response(400, NULL, Kohana::lang('contact.group_name_too_long'));
} elseif ($this->model->check_name($this->user_id, $name, $id)) {
$this->send_response(400, NULL, Kohana::lang('contact.group_name_exist'));
} else {
$status = $this->model->edit($this->user_id, $name, $id);
if ($status == FALSE) {
$this->send_response(404, NULL, Kohana::lang('contact.group_not_exist'));
} else {
$this->send_response(200, array('id' => (int) $id, 'name' => $name), '', FALSE);
}
}
}