模型,修改自动完成字段
<?php namespace appdemomodel; use thinkModel; class Student extends Model{ 获取器 public function getSsexAttr($val){ switch($val){ case 1: return "男"; break; case 2: return "女"; break; default: return "未知"; break; } } 修改器 public function setClassAttr($val){ return md5($val); } public $auto = ['Sno','Ssex']; public function setSnoAttr(){ return 8; } public function setSsexAttr(){ return 2222; } } ?>
控制层
<?php namespace appdemocontroller; use thinkController; use appdemomodelStudent;//引入模型 class Demo extends Controller{ public function test(){ //得到student表中id为1的信息 $student = new Student; //dump($student->get(1)->toArray()); 打印看结果
其他操作方式见tp5手册
?>