I believe that users who have used thinkphp know that the thinkphp model can complete many auxiliary functions, such as automatic verification, automatic completion, etc. Today, during development, I encountered the function of obtaining the session value and then automatically assigning the value in the automatic completion. Please refer to the code for details;
class ArticlelModel extends Model { protected $_auto = array ( array('addtime','time',1,'function'), array('username','getName',1,'callback') ); //这个函数获取session里的name值 protected function getName(){ return $_SESSION["name"]; } }
Here you need to pay attention to the difference between the last parameter function and callback;
function: when using a function, it will automatically go to Common/common.php to find the corresponding function;
callback: use the callback method defined in the current model
For more related articles about thinkphp automatically completing session assignment sample code in the model, please pay attention to the PHP Chinese website!