Home > Backend Development > PHP Tutorial > thinkphp在模型中自动完成session赋值示例代码_php技巧

thinkphp在模型中自动完成session赋值示例代码_php技巧

WBOY
Release: 2016-05-16 20:36:25
Original
1075 people have browsed it

相信用过thinkphp的用户都知道thinkphp的模型可以完成很多辅助功能,比如自动验证、自动完成等,今天在开发中遇到自动完成中需要获取session值然后自动赋值的功能,具体看代码;

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

这里需要注意最后一个参数function和callback的区别;
function:使用函数,会自动去Common/common.php去寻找对应的函数;
callback:使用在当前模型中定义的回调方法

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template