Example #1
0
 public function loadCategory($str_category)
 {
     $categoryArr = explode($this->limit, $str_category);
     array_pop($categoryArr);
     array_shift($categoryArr);
     $id_parent = 1;
     $category_paths = array();
     foreach ($categoryArr as $name) {
         if (!($result = $this->_catelogExists($name, $id_parent))) {
             $category = new Category();
             $category->copyFromPost();
             $category->name = pSQL($name);
             $category->active = 1;
             $category->id_parent = (int) $id_parent;
             $category->rewrite = pSQL(preg_replace("/[^-0-9a-zA-Z]+/", "", str_replace(' ', '-', trim($name))));
             $category->add();
             $id_parent = $category->id;
             unset($category);
         } else {
             $id_parent = $result;
         }
         $category_paths[] = $id_parent;
     }
     return $category_paths;
 }
Example #2
0
<!--head-->
<script type="text/javascript" src="../js/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="../js/tinymce/tinymce.init.js"></script>
<!--//head-->
<?php 
if (isset($_POST['sveCategory']) && Tools::getRequest('sveCategory') == 'add') {
    $cmscategory = new Category();
    $cmscategory->copyFromPost();
    $cmscategory->add();
    if (is_array($cmscategory->_errors) and count($cmscategory->_errors) > 0) {
        $errors = $cmscategory->_errors;
    } else {
        $_GET['id'] = $cmscategory->id;
        UIAdminAlerts::conf('创建分类成功');
    }
}
if (isset($_GET['id'])) {
    $id = (int) $_GET['id'];
    $obj = new Category($id);
}
if (isset($_POST['sveCategory']) && Tools::getRequest('sveCategory') == 'edit') {
    if (Tools::getRequest('id_parent') == $obj->id) {
        $obj->_errors[] = '父分类不能为当前分类!';
    } elseif (Validate::isLoadedObject($obj)) {
        $obj->copyFromPost();
        $obj->update();
    }
    if (is_array($obj->_errors) and count($obj->_errors) > 0) {
        $errors = $obj->_errors;
    } else {
        UIAdminAlerts::conf('更新分类成功');