


Typecho plug-in writing tutorial (3): Save configuration, typecho plug-in_PHP tutorial
Typecho plug-in writing tutorial (3): Save configuration, typecho plug-in
We made a bare plug-in in the previous section, now we start to make our plug-in work!
I. Improve the method
Two methods
We implement the activate and deactivate methods
Copy code 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
Copy code 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 are the access keys stored? Of course it's 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 following figure 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
Copy code 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.
Copy code 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)
# Omit the following
III. Issues needing attention when using
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
From var/Widget/Plugins/Edit.php we learned a lot of advanced usage of forms, 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

AI Hentai Generator
Generate AI Hentai for free.

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



PyCharm is a powerful and popular Python integrated development environment (IDE) that provides a wealth of functions and tools so that developers can write code more efficiently. The plug-in mechanism of PyCharm is a powerful tool for extending its functions. By installing different plug-ins, various functions and customized features can be added to PyCharm. Therefore, it is crucial for newbies to PyCharm to understand and be proficient in installing plug-ins. This article will give you a detailed introduction to the complete installation of PyCharm plug-in.
![Error loading plugin in Illustrator [Fixed]](https://img.php.cn/upload/article/000/465/014/170831522770626.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
When launching Adobe Illustrator, does a message about an error loading the plug-in pop up? Some Illustrator users have encountered this error when opening the application. The message is followed by a list of problematic plugins. This error message indicates that there is a problem with the installed plug-in, but it may also be caused by other reasons such as a damaged Visual C++ DLL file or a damaged preference file. If you encounter this error, we will guide you in this article to fix the problem, so continue reading below. Error loading plug-in in Illustrator If you receive an "Error loading plug-in" error message when trying to launch Adobe Illustrator, you can use the following: As an administrator

What is the Chrome plug-in extension installation directory? Under normal circumstances, the default installation directory of Chrome plug-in extensions is as follows: 1. The default installation directory location of chrome plug-ins in windowsxp: C:\DocumentsandSettings\username\LocalSettings\ApplicationData\Google\Chrome\UserData\Default\Extensions2. chrome in windows7 The default installation directory location of the plug-in: C:\Users\username\AppData\Local\Google\Chrome\User

When users use the Edge browser, they may add some plug-ins to meet more of their needs. But when adding a plug-in, it shows that this plug-in is not supported. How to solve this problem? Today, the editor will share with you three solutions. Come and try it. Method 1: Try using another browser. Method 2: The Flash Player on the browser may be out of date or missing, causing the plug-in to be unsupported. You can download the latest version from the official website. Method 3: Press the "Ctrl+Shift+Delete" keys at the same time. Click "Clear Data" and reopen the browser.

How to use C# to write a Bloom filter algorithm. The Bloom Filter (BloomFilter) is a very space-efficient data structure that can be used to determine whether an element belongs to a set. Its basic idea is to map elements into a bit array through multiple independent hash functions and mark the bits of the corresponding bit array as 1. When judging whether an element belongs to the set, you only need to judge whether the bits of the corresponding bit array are all 1. If any bit is 0, it can be judged that the element is not in the set. Bloom filters feature fast queries and

Does PyCharm Community Edition support enough plugins? Need specific code examples As the Python language becomes more and more widely used in the field of software development, PyCharm, as a professional Python integrated development environment (IDE), is favored by developers. PyCharm is divided into two versions: professional version and community version. The community version is provided for free, but its plug-in support is limited compared to the professional version. So the question is, does PyCharm Community Edition support enough plug-ins? This article will use specific code examples to

How to write exponentiation function in C language Exponentiation (exponentiation) is a commonly used operation in mathematics, which means multiplying a number by itself several times. In C language, we can implement this function by writing a power function. The following will introduce in detail how to write a power function in C language and give specific code examples. Determine the input and output of the function The input of the power function usually contains two parameters: base and exponent, and the output is the calculated result. therefore, we

Installation steps: 1. Open PyCharm and click the "File" option in the top menu bar; 2. Select "Settings"; 3. In the settings window, select the "Plugins" option; 4. Click the "Browse repositories..." button. You will see all available plug-ins; 5. Enter the name of the plug-in you want to install in the search box, and then click the "Search button"; 6. Find the plug-in you want to install, and click the "Install" button to the right of the plug-in name; 7 , restart after the installation is complete.
