插件存储

在typecho中已经帮我吗实现了数据存储的功能,我们只需要调用Typecho_Widget_Helper_Form类就可以实现数据的存储

在插件Plugin.php文件中的config方法保存我们需要的内容,比如说实现发布文章,在企业微信中就能收到通知。

        /**
     * 获取插件配置面板
     * 
     * @access public
     * @param Typecho_Widget_Helper_Form $form 配置面板
     * @return void
     */
    public static function config(Typecho_Widget_Helper_Form $form)
    {
         /** 表单名称 */
        $name = new Typecho_Widget_Helper_Form_Element_Text('api', NULL, '这里是机器人链接', _t('企业机器人调用地址'));
        $form->addInput($name);
    }

Typecho_Widget_Helper_Form_Element_Text:是表单基类,地址在:var/Typecho/Widget/Helper/Form/Element.php:111

构造方法如下:

         /**
     * 构造函数
     *
     * @param string|null $name 表单输入项名称
     * @param array|null $options 选择项
     * @param mixed $value 表单默认值
     * @param string|null $label 表单标题
     * @param string|null $description 表单描述
     * @return void
     */
    public function __construct(
        ?string $name = null,
        ?array $options = null,
        $value = null,
        ?string $label = null,
        ?string $description = null
    )

只需要传入参数:表单输入项名称选择项表单默认值表单标题表单描述

注意事项

  • 修改表单名称需要重新启动插件才能生效,因为插件启用后,表单内容就持久化到数据库中了,禁用插件才能清空该插件的表单设置。
最后修改:2024 年 05 月 24 日
如果觉得我的文章对你有用,请随意赞赏