Table of Contents
typecho插件编写教程(三):保存配置
Home php教程 php手册 typecho插件编写教程(三):保存配置

typecho插件编写教程(三):保存配置

Jun 13, 2016 am 09:03 AM
typecho three main keep plug-in Tutorial article write Configuration

typecho插件编写教程(三):保存配置

   这篇文章主要介绍了typecho插件编写教程(三):保存配置,本文讲解了完善方法、如何保存配置、使用需要注意的问题等内容,需要的朋友可以参考下

  上一节我们制作了一个裸插件,下面我们开始让我们的插件开始工作!

  I. 完善方法

  两个方法

  我们实现activate和deactivate方法

   代码如下:

  public static function activate(){

  return 'activate';

  }

  public static function deactivate(){

  return 'deactivated';

  }

  如上代码所示,我们在激活和卸载插件方法中有返回值,所以在相应操作时会有相应的提示。

  完善信息,使其更接地气

   代码如下:

  public static function activate(){

  // do something

  return '插件安装成功,请进入设置填写准入密钥';

  }

  public static function deactivate(){

  // do something

  return '插件卸载成功';

  }

  II. 如何保存配置

  准入密钥在哪里保存?当然是数据库了。

  typecho已经为我们实现了Typecho_Widget_Helper_Form类,我们只需要一点代码就可以摆脱需要自己写表单的烦恼了。

  下图是表单类的继承关系,我们可以使用很多类型的表单来保存我们的选项。

  下面我们在config方法中保存 接口调用地址,类似如下链接(你可以在百度站长平台的链接提交里找到)

  接口调用地址:http://data.zz.baidu.com/urls?site=www.phpgao.com&token=5wK0QtGCzdRzufvW

   代码如下:

  public static function config(Typecho_Widget_Helper_Form $form){

  //保存接口调用地址

  $element = new Typecho_Widget_Helper_Form_Element_Text('api', null, null, _t('接口调用地址'), '请登录百度站长平台获取');

  $form->addInput($element);

  }

  初始化参数有5个,他们都是做什么的?

  以下是表单基类的构造方法,他们的功能分别是表单输入项名称、选择项、表单默认值、表单标题、表单描述。

   代码如下:

  # var/Typecho/Widget/Helper/Form/Element.php:111

  /**

  * 构造函数

  *

  * @access public

  * @param string $name 表单输入项名称

  * @param array $options 选择项

  * @param mixed $value 表单默认值

  * @param string $label 表单标题

  * @param string $description 表单描述

  * @return void

  */

  public function __construct($name = NULL, array $options = NULL, $value = NULL, $label = NULL, $description = NULL)

  # 以下省略

  III. 使用需要注意的问题

  修改表单名称($name)后需要重启插件才能工作,因为插件启用后,表单内容就持久化到数据库中了,禁用插件才能清空该插件的表单设置

  Typecho_Widget_Helper_Form_Element_Fake 不用理会

  由var/Widget/Plugins/Edit.php我们学到很多表单的高级用法,以后老高会在合适的时候提到

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tutorial on how to use Dewu Tutorial on how to use Dewu Mar 21, 2024 pm 01:40 PM

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

How to save pictures without watermark in Xiaohongshu How to save pictures without watermark in Xiaohongshu How to save pictures without watermark in Xiaohongshu How to save pictures without watermark in Xiaohongshu Mar 22, 2024 pm 03:40 PM

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

How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! Mar 15, 2024 pm 04:13 PM

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,

Understand Linux Bashrc: functions, configuration and usage Understand Linux Bashrc: functions, configuration and usage Mar 20, 2024 pm 03:30 PM

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

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

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.

How to download and save Douyin videos How to download and save Douyin videos Mar 29, 2024 pm 02:16 PM

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.

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

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.

How to save the videos of the video account to the photo album? Method sharing How to save the videos of the video account to the photo album? Method sharing Mar 26, 2024 am 11:21 AM

Video account is a popular short video application that allows users to shoot, edit and share their own videos. However, sometimes we may want to save these amazing videos to our photo album so that we can always look back at them when needed. So, next I will share some methods to teach you how to save the video of the video account to the album. Videos can be saved through the built-in function of the Video Number application. Open the app and find the video you want to save. Click the options icon in the lower right corner of the video, a menu will pop up, select "Save to Album". This will save the video to your phone's photo album. Method two is to save the video by taking a screenshot. This method is relatively straightforward, but the saved image will contain elements such as video control bars, which is not pure enough. you

See all articles