php34-2-2添加商品分类的页面的无限极分类的总结

php34-2-2添加商品分类的页面的无限极分类的总结

添加商品分类的页面cat_add.html原本是从ecshop里面复制过来,
$cat是通过继承baseModel的catModel的getALLList(select from *)里面过来的。
select 选项改了一下 加进去了<?php foreach($cats as $cat):?>
<option value = "<?php echo $cat['cat_id']?>"><?php echo $cat['cat_name']?></option>

在我们的基础模型中,定义了几个自动方法,包括自动插入、更新和删除。

这个add的view调用的是category的insert的action,插入同一个table,靠parent_id区分(父分类)父节点 就实现了无限极分类
catModel里面的getAll()方法示例:
    public function getCats(){
        $sql = "SELECT * FROM {$this->table}";
        $cats =  $this->db->getAll($sql);
        return $this->tree($cats);
    }

$this->table 里面的this指的是当前调用的controller的prefix, table是调用者model继承自base基础的Model里面的field属性table里面得到的,base的Model的class里面的__construct构造方法里面查看发现:
    public function __construct($table){
        $dbconfig['host'] = $GLOBALS['config']['host'];
        $dbconfig['user'] = $GLOBALS['config']['user'];
        $dbconfig['password'] = $GLOBALS['config']['password'];
        $dbconfig['dbname'] = $GLOBALS['config']['dbname'];
        $dbconfig['port'] = $GLOBALS['config']['port'];
        $dbconfig['charset'] = $GLOBALS['config']['charset'];

        $this->db = new Mysql($dbconfig);
        $this->table = $GLOBALS['config']['prefix'] . $table;

        //调用getFields字段
        $this->getFields();
    }
显然$table从外部传参进入,与超全局常量配置config数组的"prefix" => "cz_"连接this后得到,没有指定this则默认为controller的prifix前缀

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值