Home > Backend Development > PHP Tutorial > thinkphp程序的插件机制原理一般是怎么实现的呢?如wordpress插件,DZ!插件等

thinkphp程序的插件机制原理一般是怎么实现的呢?如wordpress插件,DZ!插件等

WBOY
Release: 2016-06-06 20:35:55
Original
1547 people have browsed it

php程序的插件机制原理一般是怎么实现的呢?如wordpress插件,DZ!插件等

thinkphp的系统钩子,标签位算插件吗,插件控制器又是怎么回事呢?

自己怎么开发插件呢,插件实现的原理都不懂,真心纠结,有知道的帮忙解惑,感激不尽!

回复内容:

php程序的插件机制原理一般是怎么实现的呢?如wordpress插件,DZ!插件等

thinkphp的系统钩子,标签位算插件吗,插件控制器又是怎么回事呢?

自己怎么开发插件呢,插件实现的原理都不懂,真心纠结,有知道的帮忙解惑,感激不尽!

给你写一段简单的代码你就懂了,

<code>php</code><code><?php $func = array();

 function do_action($name){
     global $func;
     if(isset($func[$name])){
         for($i=0; $i< count($func[$name]); $i++){
             $func[$name][$i]();
         }
      }
 }

function add_action($name, $call_name){
    global $func;
    $func[$name][] = $call_name; 
}
?>
</code>
Copy after login

然后通过do_action添加钩子,add_action实现插件函数调用

你可以了解下 注册设计模式 就是用这个实现的

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