Typecho Plugin Authoring Tutorial (iii): Save Configuration _php Instance

Source: Internet
Author: User

In the previous section we have made a bare plugin, below we start to let our plugin begin to work!

I. Perfecting Methods

Two methods

We implement activate and Deactivate methods

Copy Code code as follows:

public static function activate () {
return ' activate ';
}

public static function deactivate () {
return ' deactivated ';
}


As shown in the code above, we have the return value in the activation and unload plug-in method, so there is a corresponding prompt when the action is taken.

Perfect information to make it more grounded gas

Copy Code code as follows:

public static function activate () {
Do something
Return ' plugin installed successfully, please enter the set Fill entry key ';
}

public static function deactivate () {
Do something
Return ' plugin uninstall succeeded ';
}

Ii. How to save the configuration

Where is the access key saved? Of course it's the database.

Typecho has already implemented the Typecho_widget_helper_form class for us, we just need a little bit of code to get rid of the trouble of having to write our own forms.

The following figure is the inheritance of a form class, and we can use many types of table forms to save our options.

Below we in the Config method to save the interface call address, similar to the following link (you can in Baidu Webmaster Platform link submitted to find)

Interface Invocation Address: Http://data.zz.baidu.com/urls?site=www.phpgao.com&token=5wK0QtGCzdRzufvW

Copy Code code as follows:

public static function config (Typecho_widget_helper_form $form) {
Save Interface Call Address
$element = new Typecho_widget_helper_form_element_text (' API ', NULL, NULL, _t (' Interface call address '), ' please login to Baidu Webmaster platform to get ');
$form->addinput ($element);
}

There are 5 initialization parameters, what do they do?

The following are the construction methods for the table single classes, which are the form entry name, the selection, the form default, the form title, and the form description.

Copy Code code as follows:

# var/typecho/widget/helper/form/element.php:111

/**
* Constructor
*
* @access Public
* @param string $name form entry name
* @param array $options selection
* @param mixed $value form default values
* @param string $label form title
* @param string $description form Description
* @return void
*/
Public function __construct ($name = null, array $options = NULL, $value = NULL, $label = NULL, $description = NULL)
# The following omitted

Iii. use of issues to be noted

After you modify the form name ($name), you need to restart the plug-in to work because the form content is persisted to the database after the plug-in is enabled, disabling the plug-in to empty the plug-in's form settings
Typecho_widget_helper_form_element_fake Don't bother.
by var/widget/plugins/edit.php We have learned a lot about the advanced usage of forms, which will be mentioned at the right time.

Related Article

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.