本文整理汇总了PHP中Category_Model::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Category_Model::add方法的具体用法?PHP Category_Model::add怎么用?PHP Category_Model::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category_Model
的用法示例。
在下文中一共展示了Category_Model::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Создаёт новую категорию
* @param $args array mixed
* @return void
*/
function add(array $args = array())
{
$category = array('system' => 0, 'parent' => 0);
$types = array_flip(Category::getTypesArray());
if (array_key_exists(0, $args) && array_key_exists($args[0], $types)) {
$category['type'] = $types[$args[0]];
} else {
$category['type'] = Category::TYPE_WASTE;
}
if ($this->request->method == 'POST') {
$errors = array();
$category = array('name' => trim($this->request->post['name']), 'parent' => (int) $this->request->post['parent'], 'system' => (int) $this->request->post['system'], 'type' => isset($this->request->post['type']) ? $this->request->post['type'] : $category['type']);
if (!$category['name']) {
$errors[] = 'Не указано название!';
}
if (!$category['system']) {
$errors[] = 'Не указана системная категория!';
}
if (!array_key_exists($category['type'], Category::getTypesArray())) {
$errors[] = 'Некорректный тип категории!';
}
if (!sizeof($errors)) {
$category['id'] = $this->model->add($category['name'], $category['parent'], $category['system'], $category['type']);
$this->tpl->assign('result', array('text' => "Категория успешно добавлена.", 'id' => $category['id']));
} else {
$this->tpl->assign('error', array('text' => implode(" \n", $errors)));
}
}
$this->tpl->assign('category', $category);
$this->tpl->assign('name_page', 'category/edit');
}
示例2: create
/**
* 创建联系人分组
*/
public function create()
{
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'] : '';
if (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'));
} else {
if ($this->model->check_name($this->user_id, $name)) {
$this->send_response(400, NULL, Kohana::lang('contact.group_name_exist'));
} else {
$gid = $this->model->add($this->user_id, $name);
$result = array('id' => (int) $gid, 'name' => $name);
$this->send_response(200, $result);
}
}
}