In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces you how to write the typecho plug-in to save the configuration of the code introduction, the content is very detailed, interested friends can refer to, I hope you can help.
i. Perfect method
Two methods
We implement the activate and deactivate methods
The copy code is 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 method of activating and uninstalling the plug-in, so we will be prompted for the appropriate action.
Improve the information to make it more approachable
The copy code is as follows:
Public static function activate () {
/ / do something
Return 'plug-in installed successfully, enter the settings and fill in the admission key'
}
Public static function deactivate () {
/ / do something
Return 'plug-in uninstalled successfully'
}
ii. How to save a configuration
Where is the access key saved? The database, of course.
Typecho has implemented the Typecho_Widget_Helper_Form class for us, and we only need a little code to get rid of the hassle of writing our own forms.
The following figure shows the inheritance of the form class, and we can use many types of forms to save our options.
Next, we save the API call address in the config method, similar to the following link (you can find it in the link submission of Baidu webmaster platform)
API call address: http://data.zz.baidu.com/urls?site=www.phpgao.com&token=5wK0QtGCzdRzufvW
The copy code is as follows:
Public static function config (Typecho_Widget_Helper_Form $form) {
/ / Save the API call address
$element = new Typecho_Widget_Helper_Form_Element_Text ('api', null, null, _ t (' API call address'), 'Please log in to Baidu webmaster platform to get it')
$form- > addInput ($element)
}
There are five initialization parameters. What do they do?
The following is the construction method of the form base class, and their functions are form input name, selection, form default value, form title, and form description.
The copy code is as follows:
# var/Typecho/Widget/Helper/Form/Element.php:111
/ * *
* Constructor
*
* @ access public
* @ param string $name form entry name
* @ param array $options option
* @ param mixed $value form default
* @ 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 ellipses
iii. Problems needing attention in use
The plug-in needs to be restarted to work after modifying the form name ($name), because after the plug-in is enabled, the form content is persisted to the database, and the plug-in is disabled to clear the plug-in's form settings
Don't worry about Typecho_Widget_Helper_Form_Element_Fake.
We have learned a lot about the advanced use of forms from var/Widget/Plugins/Edit.php, which will be mentioned by Lao Gao in the future.
On the typecho plug-in how to write and save the configuration of the code to share here, I hope the above can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.