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
where('id='.$id)->find(); }}
5、调用model,indexCrl.php
select(); var_dump($data); $data2=$model->findId(1); var_dump($data2); }}
来源地址:https://blog.csdn.net/weixin_39934453/article/details/132241663