typecho 插件接口怎样使用?

WBOY
Release: 2016-06-06 20:41:54
Original
1567 people have browsed it

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

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

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

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

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

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

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

回复内容:

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

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

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

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

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

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

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

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

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

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

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

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!