How to add multiple actions to the same plug-in?

Source: Internet
Author: User
For example, I have a plug-in named Test {code...}. I want to add two actions: Test and Custom .. In this way, it is normal to access actionTest, but an error is reported when you access actionCustom, indicating that no action can be found. Can I add two actions to a plug-in? If you can... for example, I have a plug-in called 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    }    ...    ..    .}

I want to add two actions: Test and Custom ..
In this way, it is normal to access action/Test, but an error is reported when you access action/Custom, indicating that no action can be found.

Can I add two actions to a plug-in? If yes, how do I write code?

Reply content:

For example, I have a plug-in calledTest

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    }    ...    ..    .}

I want to add two actions: Test and Custom ..
In this way, it is normal to access action/Test, but an error is reported when you access action/Custom, indicating that no action can be found.

Can I add two actions to a plug-in? If yes, how do I write code?

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;    }}

No. The include path of the Custom_Action file is Custom/Action. php, and the class name is Custom_Action.

A single action can handle everything. If you need to add an action, you can only add a new plugins to define it based on the action access principle.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.