当前位置:Gxlcms > PHP教程 > typecho插件接口怎样使用?

typecho插件接口怎样使用?

时间:2021-07-01 10:21:17 帮助过:49人阅读

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

navBar(); ?>

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

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

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

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

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

回复内容:

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

navBar(); ?>

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

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

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

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

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

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

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

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

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

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

人气教程排行