Home > php教程 > PHP开发 > thinkphp automatically completes session assignment sample code in the model

thinkphp automatically completes session assignment sample code in the model

高洛峰
Release: 2016-12-22 10:27:46
Original
1299 people have browsed it

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"];
}
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template