利用ThinkPHP的举动扩展做系统日志

WBOY
Release: 2016-06-13 12:23:53
Original
1183 people have browsed it

利用ThinkPHP的行为扩展做系统日志

1:模块配置:

<?phpreturn array(    &#39;action_end&#39; => array('Admin\\Behaviors\\LogBehavior'),);
Copy after login

2:数据库建表:

create table logs(	id int(11) primary key auto_increment,	url char(30) not null,	operator int(11) not null,	description char(60) not null,	operate_time int(10) not null)charset=utf8 engine=myisam;
Copy after login
3:行为类编写:

<?phpnamespace Admin\Behaviors;use Think\Behavior;class LogBehavior extends Behavior{	public function run(&$params){		$data[&#39;url&#39;] = substr(__ACTION__, strpos(__ACTION__, &#39;index.php&#39;)+strlen(&#39;index.php&#39;));		$data[&#39;operator&#39;] = intval(session(&#39;admin_id&#39;));		$data[&#39;operate_time&#39;] = time();		$node = M(&#39;data_node&#39;)->where(array('m_c_a'=>$data['url']))->find();		$data['description'] = $node['node_name'];		// var_dump(APP_DEBUG);		M('logs')->add($data);	}}?>
Copy after login
4:效果展示:



版权声明:没有什么版权不版权的,如果你喜欢,拿去用。

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