Home > Backend Development > PHP Tutorial > 如何在同一个插件中添加多个action?

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

WBOY
Release: 2016-06-06 20:46:31
Original
1283 people have browsed it

比如我有个插件,叫做Test

<code class="lang-php">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
    }
    ...
    ..
    .
}
</code>
Copy after login
Copy after login

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

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

回复内容:

比如我有个插件,叫做Test

<code class="lang-php">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
    }
    ...
    ..
    .
}
</code>
Copy after login
Copy after login

我想添加两个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>
Copy after login

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

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

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