欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2023-12-31 19:46:22
...
比如我有个插件,叫做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代码

if (isset($widgetName) && class_exists($widgetName)) {
    $reflectionWidget =  new ReflectionClass($widgetName);
    if ($reflectionWidget->implementsInterface('Widget_Interface_Do')) {
        $this->widget($widgetName)->action();
        return;
    }
}

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

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

相关标签: typecho php

上一篇:

下一篇: