Home\Controller\CatalogController::save PHP Метод

save() публичный Метод

保存目录
public save ( )
    public function save()
    {
        $cat_name = I("cat_name");
        $s_number = I("s_number/d") ? I("s_number/d") : 99;
        $cat_id = I("cat_id/d") ? I("cat_id/d") : 0;
        $parent_cat_id = I("parent_cat_id/d") ? I("parent_cat_id/d") : 0;
        $item_id = I("item_id/d");
        $login_user = $this->checkLogin();
        if (!$this->checkItemPermn($login_user['uid'], $item_id)) {
            $this->message(L('no_permissions'));
            return;
        }
        $data['cat_name'] = $cat_name;
        $data['s_number'] = $s_number;
        $data['item_id'] = $item_id;
        $data['parent_cat_id'] = $parent_cat_id;
        if ($parent_cat_id > 0) {
            $data['level'] = 3;
        } else {
            $data['level'] = 2;
        }
        if ($cat_id > 0) {
            $ret = D("Catalog")->where(" cat_id = '{$cat_id}' ")->save($data);
            $return = D("Catalog")->where(" cat_id = '{$cat_id}' ")->find();
        } else {
            $data['addtime'] = time();
            $cat_id = D("Catalog")->add($data);
            $return = D("Catalog")->where(" cat_id = '{$cat_id}' ")->find();
        }
        if (!$return) {
            $return['error_code'] = 10103;
            $return['error_message'] = 'request  fail';
        }
        $this->sendResult($return);
    }