


Typecho plug-in writing tutorial (3): Saving configuration_PHP tutorial
Typecho plug-in writing tutorial (3): Saving configuration
This article mainly introduces the typecho plug-in writing tutorial (3): Saving configuration. This article explains the improvement method and how to save it. For configuration and usage issues that need attention, friends in need can refer to it
We made a bare plug-in in the previous section, now let’s start making our plug-in work!
I. Improve the method
Two methods
We implement the activate and deactivate methods
The code is as follows:
public static function activate(){
return 'activate';
}
public static function deactivate(){
return 'deactivated';
}
As shown in the above code, we have return values in the activation and uninstallation plug-in methods, so there will be corresponding prompts during the corresponding operations.

Improve the information and make it more down-to-earth
The code is as follows:
public static function activate(){
// do something
Return 'The plug-in is installed successfully, please enter the settings to fill in the access key';
}
public static function deactivate(){
// do something
return 'Plug-in uninstalled successfully';
}
II. How to save configuration
Where is the access key stored? Of course it is the database.
Typecho has implemented the Typecho_Widget_Helper_Form class for us. We only need a little code to get rid of the trouble of writing the form ourselves.
The picture below shows the inheritance relationship of the form class. We can use many types of forms to save our options.
Next 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 calling address: http://data.zz.baidu.com/urls?site=www.phpgao.com&token=5wK0QtGCzdRzufvW
The code is as follows:
Public static function config(Typecho_Widget_Helper_Form $form){
//Save the interface calling address
$element = new Typecho_Widget_Helper_Form_Element_Text('api', null, null, _t('Interface call address'), 'Please log in to Baidu Webmaster Platform to obtain');
$form->addInput($element);
}
There are 5 initialization parameters. What do they do?
The following is the construction method of the form base class. Their functions are form input name, selection item, form default value, form title, and form description.
The code is as follows:
# var/Typecho/Widget/Helper/Form/Element.php:111
/**
* Constructor
*
* @access public
* @param string $name form input name
* @param array $options options
* @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)
# The following is omitted
III. Issues needing attention during use
After modifying the form name ($name), you need to restart the plug-in to work, because after the plug-in is enabled, the form content is persisted to the database. Only by disabling the plug-in can the plug-in's form settings be cleared
Typecho_Widget_Helper_Form_Element_Fake Ignore
We learned a lot of advanced usage of forms from var/Widget/Plugins/Edit.php, which I will mention at the appropriate time in the future

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Dewu APP is currently a very popular brand shopping software, but most users do not know how to use the functions in Dewu APP. The most detailed usage tutorial guide is compiled below. Next is the Dewuduo that the editor brings to users. A summary of function usage tutorials. Interested users can come and take a look! Tutorial on how to use Dewu [2024-03-20] How to use Dewu installment purchase [2024-03-20] How to obtain Dewu coupons [2024-03-20] How to find Dewu manual customer service [2024-03-20] How to check the pickup code of Dewu [2024-03-20] Where to find Dewu purchase [2024-03-20] How to open Dewu VIP [2024-03-20] How to apply for return or exchange of Dewu

Xiaohongshu has rich content that everyone can view freely here, so that you can use this software to relieve boredom every day and help yourself. In the process of using this software, you will sometimes see various beautiful things. Many people want to save pictures, but the saved pictures have watermarks, which is very influential. Everyone wants to know how to save pictures without watermarks here. The editor provides you with a method for those in need. Everyone can understand and use it immediately! 1. Click the "..." in the upper right corner of the picture to copy the link 2. Open the WeChat applet 3. Search the sweet potato library in the WeChat applet 4. Enter the sweet potato library and confirm to get the link 5. Get the picture and save it to the mobile phone album

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

1. Open the Douyin app, find the video you want to download and save, and click the [Share] button in the lower right corner. 2. In the pop-up window that appears, slide the function buttons in the second row to the right, find and click [Save Local]. 3. A new pop-up window will appear at this time, and the user can see the download progress of the video and wait for the download to complete. 4. After the download is completed, there will be a prompt of [Saved, please go to the album to view], so that the video just downloaded will be successfully saved to the user's mobile phone album.

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

PhotoshopCS is the abbreviation of Photoshop Creative Suite. It is a software produced by Adobe and is widely used in graphic design and image processing. As a novice learning PS, let me explain to you today what software photoshopcs5 is and how to use photoshopcs5. 1. What software is photoshop cs5? Adobe Photoshop CS5 Extended is ideal for professionals in film, video and multimedia fields, graphic and web designers who use 3D and animation, and professionals in engineering and scientific fields. Render a 3D image and merge it into a 2D composite image. Edit videos easily
