Typecho Plugin Authoring Tutorial (iii): Save configuration, Typecho plugin _php tutorial

Source: Internet
Author: User

Typecho Plugin Authoring Tutorial (iii): Save configuration, Typecho plugin


The previous section we made a bare plug-in, below we began to let our plug-in began to work!

I. Ways to Improve

Two methods

We implement the Activate and Deactivate methods
Copy the Code code as follows:
public static function activate () {
return ' activate ';
}

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

As shown in the code above, we have a return value in the Activate and unload plug-in method, so there is a corresponding prompt in the corresponding operation.

Perfect information to make it more grounded gas
Copy the Code code as follows:
public static function activate () {
Do something
Return ' plugin installed successfully, please enter the settings to fill in the access 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 implemented the Typecho_widget_helper_form class for us, and we just need a little bit of code to get rid of the hassle of having to write our own forms.

Is the inheritance of the form class, we can use many types of table forms to save our options.

Below we save the interface call address in the Config method, similar to the following link (you can find it in the link submission of Baidu Webmaster platform)

Interface Call Address: Http://data.zz.baidu.com/urls?site=www.phpgao.com&token=5wK0QtGCzdRzufvW
Copy the 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?

Here's how the table single classes are constructed, with their functionality being the form entry name, selection, form default value, form title, and form description.
Copy the Code code as follows:
# var/typecho/widget/helper/form/element.php:111

/**
* Constructor function
*
* @access Public
* @param string $name form entry name
* @param array $options selection
* @param mixed $value form default value
* @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)
# omitted below

Iii. use of issues needing attention

After you modify the form name ($name), you need to restart the plugin to work because the form content is persisted to the database after the plug-in is enabled, disabling the plugin to empty the plugin's form settings
Typecho_widget_helper_form_element_fake, don't bother.
By var/widget/plugins/edit.php we learned a lot of advanced usage of forms, and later the old high will be mentioned at the right time.

http://www.bkjia.com/PHPjc/1008008.html www.bkjia.com true http://www.bkjia.com/PHPjc/1008008.html techarticle Typecho Plugin Programming Tutorial (iii): Save the configuration, Typecho plugin on the previous section we made a bare plug-in, below we start to let our plug-in start to work! I. Methods of improvement two parties ...

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