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前缀
	

  

posted @ 2017-05-08 23:48  影落明湖  阅读(1064)  评论(0编辑  收藏  举报