1、实现model使用效果
2、自动加载model,KJ.php
//自动加载文件public static function _autoload($className){switch ($className){//自动model类case substr($className,-5)=='Model':$path= MODEL.'/'.$className.'.php';if(is_file($path)) include $path;break;//自动加载控制器case substr($className,-3)=='Crl':$path= CONTROLLER.'/'.$className.'.php';if(is_file($path)) include $path;break;//自动加载基类case substr($className,-4)=='Base':$path= KJ_CORE.'/base/'.$className.'.php';if(is_file($path)) include $path;break;default :break;}}
3、model可定义table,ModelBase.php
public function __construct($table=null){if($table){$this->table=$table;}if(!$this->table){die("no table" );}$this->_connect();$this->_opt();}
4、创建model文件,testModel.php
<?phpclass testModel extends ModelBase{public $table='test';public function findId($id){return $this->where('id='.$id)->find();}}
5、调用model,indexCrl.php
<?php
class indexCrl{public function index(){$model=new testModel();$data=$model->select();var_dump($data);$data2=$model->findId(1);var_dump($data2);}
}