首页 > 后端开发 > php教程 > 如何在同一个插件中添加多个action?

如何在同一个插件中添加多个action?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-06 20:46:31
原创
1346 人浏览过

比如我有个插件,叫做Test

class Test_Plugin implements Typecho_Plugin_Interface {
    public static function activate() {
        Helper::addAction('Test', 'Test_Action');   //Action.php
        Helper::addAction('Custom', 'Custom_Action'); //Custom.php
    }
    ...
    ..
    .
}
登录后复制
登录后复制

我想添加两个Action,分别是Test和Custom。。
这样写,访问action/Test是正常的,但是访问action/Custom却报错,说找不到。

请问能不能在一个插件中添加两个Action?如果可以,要怎么写代码?

回复内容:

比如我有个插件,叫做Test

class Test_Plugin implements Typecho_Plugin_Interface {
    public static function activate() {
        Helper::addAction('Test', 'Test_Action');   //Action.php
        Helper::addAction('Custom', 'Custom_Action'); //Custom.php
    }
    ...
    ..
    .
}
登录后复制
登录后复制

我想添加两个Action,分别是Test和Custom。。
这样写,访问action/Test是正常的,但是访问action/Custom却报错,说找不到。

请问能不能在一个插件中添加两个Action?如果可以,要怎么写代码?

widget/do.php代码

<code>if (isset($widgetName) && class_exists($widgetName)) {
    $reflectionWidget =  new ReflectionClass($widgetName);
    if ($reflectionWidget->implementsInterface('Widget_Interface_Do')) {
        $this->widget($widgetName)->action();
        return;
    }
}
</code>
登录后复制

确实不可以,Custom_Action的文件include路径是Custom/Action.php,并且类名为Custom_Action

一个action就能够处理所有事情吧,如果需要增加action的话根据action的访问原理,你只能新增加一个plugins来定义它

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
php - typecho 的独立页面如何引入css呢?
来自于 1970-01-01 08:00:00
0
0
0
nginx - Typecho的子目录问题
来自于 1970-01-01 08:00:00
0
0
0
apache - typecho rewrite pathinfo 神奇问题
来自于 1970-01-01 08:00:00
0
0
0
php - Typecho发布文章报错
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板