微擎二级分类分析

来源:互联网 发布:单片机做成mp3 编辑:程序博客网 时间:2024/06/08 08:21

function tpl_form_field_category_pfxm2level($namepfxm, $parentpfxms, $childrenpfxm, $pingfenid1, $pingfenid2){$html = '<script type="text/javascript">window._' . $namepfxm . ' = ' . json_encode($childrenpfxm) . ';</script>';if (!defined('TPL_INIT_CATEGORYY')) {$html .= '<script type="text/javascript">function renderCategory(obj, name){var index = obj.options[obj.selectedIndex].value;require([\'jquery\', \'util\'], function($, u){$selectChild = $(\'#\'+name+\'_child\');var html = \'<option value="0">请选择二级分类</option>\';if (!window[\'_\'+name] || !window[\'_\'+name][index]) {$selectChild.html(html);return false;}for(var i=0; i< window[\'_\'+name][index].length; i++){html += \'<option value="\'+window[\'_\'+name][index][i][\'id\']+\'">\'+window[\'_\'+name][index][i][\'name\']+\'</option>\';}$selectChild.html(html);});}</script>';define('TPL_INIT_CATEGORYY', true);}$html .='<div class="row row-fix tpl-category-container"><div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"><select class="form-control tpl-category-parent we7-select" id="' . $namepfxm . '_parent" name="' . $namepfxm . '[pingfenid1]" onchange="renderCategory(this,\'' . $namepfxm . '\')"><option value="0">请选择一级分类</option>';$ops = '';if(!empty($parentpfxms)) {foreach ($parentpfxms as $row) {$html .= '<option value="' . $row['id'] . '" ' . (($row['id'] == $pingfenid1) ? 'selected="selected"' : '') . '>' . $row['name'] . '</option>';}}$html .= '</select></div><div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"><select class="form-control tpl-category-child we7-select" id="' . $namepfxm . '_child" name="' . $namepfxm . '[pingfenid2]"><option value="0">请选择二级分类</option>';if (!empty($pingfenid1) && !empty($childrenpfxm[$pingfenid1])) {foreach ($childrenpfxm[$pingfenid1] as $row) {$html .= '<option value="' . $row['id'] . '"' . (($row['id'] == $pingfenid2) ? 'selected="selected"' : '') . '>' . $row['name'] . '</option>';}}$html .= '</select></div></div>';return $html;}

model.php  文件如上:


inc 函数文件中如下  

//把下面所有变量变成新带参数$categorypfxm = pdo_fetchall("SELECT id,parentid,name FROM " . tablename($this->tb_categorypfxm) . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY parentid ASC, displayorder ASC, id ASC ", array() , 'id');$parentpfxm = array();$childrenpfxm = array();if (!empty($categorypfxm)) {    $childrenpfxm = '';    foreach ($categorypfxm as $cidpfxm => $catepfxm) {        if (!empty($catepfxm['parentid'])) {            $childrenpfxm[$catepfxm['parentid']][] = $catepfxm;        } else {            $parentpfxm[$catepfxm['id']] = $catepfxm;        }    }}

post编辑页面需要返回值,还需要修订下。


//下面的IF是返回值的关键    if (!empty($id)) {        $item = pdo_fetch("SELECT * FROM " . tablename($this->tb_articleqsgl) . " WHERE id = :id", array(            ':id' => $id        ));        $item['type'] = explode(',', $item['type']);        $pcate = $item['pcate'];        $ccate = $item['ccate'];        $pingfenid1 = $item['pingfenid1'];//这里错了一个$item        $pingfenid2 = $item['pingfenid2'];//这里错了一个$item        if (empty($item)) {            message('抱歉,判分记录不存在或是已经删除!', '', 'error');        }        $item['credit'] = iunserializer($item['credit']) ? iunserializer($item['credit']) : array();                    } else {        $item['credit'] = array();    }



原创粉丝点击