Home  >  Article  >  Backend Development  >  typecho 插件接口怎样使用?

typecho 插件接口怎样使用?

WBOY
WBOYOriginal
2016-06-06 20:41:541568browse

有以下两中接口形式,第一种:

<code><?php Typecho_Plugin::factory('admin/menu.php')->navBar(); ?>
</code>

可以通过navBar = array('插件名称', '方法名称')来实现,例如:

<code>Typecho_Plugin::factory('admin/menu.php')->navBar = array('HelloWorld_Plugin', 'render');
</code>

问题是typecho更多的是第二形式接口,该接口带有参数,例如:

<code>// 完成发布插件接口
 $this->pluginHandle()->finishPublish($contents, $this);
</code>

请问,第二种形式接口跟第一种有什么区别,插件中应该怎样去写?

回复内容:

有以下两中接口形式,第一种:

<code><?php Typecho_Plugin::factory('admin/menu.php')->navBar(); ?>
</code>

可以通过navBar = array('插件名称', '方法名称')来实现,例如:

<code>Typecho_Plugin::factory('admin/menu.php')->navBar = array('HelloWorld_Plugin', 'render');
</code>

问题是typecho更多的是第二形式接口,该接口带有参数,例如:

<code>// 完成发布插件接口
 $this->pluginHandle()->finishPublish($contents, $this);
</code>

请问,第二种形式接口跟第一种有什么区别,插件中应该怎样去写?

使用方法与第一种类似,例如:

<code>Typecho_Plugin::factory('Widget_Contents_Post_Edit')->finishPublish = array('HelloWorld_Plugin', 'render');
</code>

第二种Widget接口还可以传入参数,例如下面的$contents数组及Widget_Contents_Post_Edit对象

<code>public static function render($contents, $edit)
{
    #code...
}
</code>

参考文档:http://docs.typecho.org/plugins/hooks

Statement:
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