search
HomeBackend DevelopmentPHP TutorialWhat is OneThink? OneThink background adding plug-in steps, onethink background_PHP tutorial

What is OneThink oneThink backend add plug-in steps, onethink backend

OneThink with its convenient website building, rich extensions, flexible secondary development, and The support of cloud services has brought new opportunities for individuals and enterprises to build websites, and is about to become a new trend setter on the Internet.

OneThink feature introduction:

1. Based on the latest version of ThinkPHP, Thinkphp3.2.

2. Modularity: Brand-new architecture and modular development mechanism facilitate flexible expansion and secondary development.

3. Document model/classification system: By binding to the document model and different document types, different classifications can achieve differentiated functions and easily implement functions such as information, downloads, discussions, and pictures.

4. Open source and free: OneThink follows the Apache2 open source agreement and is free for use.

5. User behavior: Supports customized user behavior, which can record and share the behavior of individual users or groups of users, providing effective reference data for your operational decisions.

6. Cloud deployment: Platform deployment can be easily supported through the driver, allowing your website to be migrated seamlessly. SAE is already supported built-in.

7. Cloud service support: Support for cloud storage, cloud security, cloud filtering, cloud statistics and other services will soon be launched. More considerate services will make your website more secure.

8. Safe and Robust: Provides a robust security strategy, including backup and recovery, fault tolerance, prevention of malicious attack login, web page anti-tampering and many other security management functions to ensure safe, reliable and stable operation of the system.

9. Application Warehouse: The official application warehouse has a large number of third-party plug-ins, application modules, template themes, and many contributions from the open source community to make your website "One" beautiful.

Steps to add plug-ins in oneThink background:

Version: V1.1.141212 (Note: There are many versions of v1.1. I accidentally downloaded it to V1.1.140202. There are other versions. It is recommended to download the latest version from the code hosting platform)

I am not lazy either, I record every step.

1. Enter the background and create a plug-in

For the hook here, I created a new indexFooter because I only need to display the friendly links at the bottom of the front page. We check all the places that need to be checked above. As for the difference, you can create a few examples to distinguish whether the generated files are the same. OK! Here our friendly link plug-in is created! Click OK. (Please leave all the custom templates blank here. I will demonstrate the effect of adding custom templates in the next article)

2. Click "Install", find the Links plug-in we just installed, click "Settings", you will see that it has a default "Whether to turn on randomization" option, we don't care about it here, because we It's no longer needed and will be deleted later. After installation, we can see our new "Friendly Links" in the left navigation "Installed Plug-in Backend"

3. When we click "Friendly Links" in the left navigation, you will find an error, which probably means that a certain table does not exist. Yes, we just built the plug-in. If it involves storing data in the database, we also need to create tables. We don’t build it directly in the database here, because doing so is very inhumane. Then we will find the function to install the plug-in and create the database when installing the plug-in. That will be fine. First, all system plug-ins are stored under the root directory /Addons/ folder. When we open this folder, we see a Links folder. This is the plug-in we just created. One plug-in corresponds to one folder. Open the Links folder, there are 2 files and 2 folders inside.

4. In fact, oneThink is becoming more and more concise now. People who don’t understand PHP can still create plug-ins, and you will find out later. Of course, if you have your own ideas and don't want to be limited to official restrictions, you still need to learn PHP well.

5. Open the plug-in entry file: LinksAddon.class.php. There is a class LinksAddon in it. Let’s analyze this file first

I changed the model value of the $admin_list array to links here in order to correspond to the plug-in. Next, we add the statement to create a new database in the install method, so that when we install the plug-in, a new database will be created. My code is as follows:

public function install(){  //安装插件的方法
    //1、添加数据表
    $model = D();
    $db_prefix = C('DB_PREFIX');
    $table_name = "{$db_prefix}links";
    
    $sql=<<<SQL
CREATE TABLE IF NOT EXISTS `$table_name` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
 `title` varchar(80) NOT NULL DEFAULT '' COMMENT '站点名称',
 `link` varchar(140) NOT NULL DEFAULT '' COMMENT '链接地址',
 `summary` varchar(255) NOT NULL DEFAULT '' COMMENT '站点描述',
 `mailto` varchar(100) NOT NULL DEFAULT '' COMMENT '站长联系方式',
 `sort` int(3) unsigned NOT NULL DEFAULT 0 COMMENT '优先级',
 `nofollow` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '是否追踪',
 `type` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '类型分组',
 `cover_id` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '封面图片',
 `status` tinyint(2) NOT NULL DEFAULT 1 COMMENT '状态(0:禁用,1:正常)',
 `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '添加时间',
 PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='友情连接表';
SQL;
  
    $model -> execute($sql);//执行sql语句
     
    //2、返回true,表示插件安装成功      
    return true;
  }

I have omitted a lot of detailed judgment here, everyone can improve it by themselves.

六、既然在安装插件的时候,新建了表,我们在卸载的插件的时候就要把表给删除,不然下次安装该插件的时候就会出问题。所以我们uninstall 方法代码如下:

public function uninstall(){ //卸载插件的方法
      $model = D();
      $db_prefix = C('DB_PREFIX');
      $table_name = "{$db_prefix}links";
      $sql="DROP TABLE IF EXISTS `".$table_name."`;";
      $model -> execute($sql);//执行sql语句  
      
      return true;
    }

好了,到这里就差不多了,保存一下LinksAddon.class.php 文件,应该可以正常显示了,我们来看看。进入插件列表,先把Links插件卸载,然后重新安装。点击左侧菜单“友情链接”,可以看到

之所以能正常显示这个列表,是因为系统有默认的模板,在\Application\Admin\View\Addons 文件夹里,有兴趣的同学可以研究一下这几个模板文件,其中这个列表的模板就是adminlist.html,那么我们要把封面、书名、描述等等这些字眼改掉,要去模板里改吗?细心的同学估计注意到了,在LinksAddon.class.php 文件 的$admin_list 数组里配置的,其他的看后面的注释就明白,这里详细说一下list_grid 关联的数组。我们刚才新建的links数据表有id、title、link等字段,你想在这个列表显示什么字段,都可以添加。我这里代码如下:

'list_grid'=>array(     //这里定义的是除了id序号外的表格里字段显示的表头名和模型一样支持函数和链接
        'title:网站名称',
        'link:链接',
        'summary:描述',
        'create_time|time_format:添加时间', //time_format 是一个函数,把时间格式化,其他地方想使用什么函数也可以按照这种格式书写
        'id:操作:[EDIT]|编辑,[DELETE]|删除'
      ),

保存,刷新后台友情链接列表

我们点击“新增” 来增加一个友情链接吧,你会发现,只有一个书名字段。我们打开Model/LinksModel.class.php 文件,我这里分别解释一下这两个自带的数组,具体看下面代码里的注释

class LinksModel extends Model{
  public $model = array(
    'title'=>'',//新增[title]、编辑[title]、删除[title]的提示
    'template_add'=>'',//自定义新增模板自定义html edit.html 会读取插件根目录的模板
    'template_edit'=>'',//自定义编辑模板html
    'search_key'=>'',// 搜索的字段名,默认是title
    'extend'=>1, //在后台列表是否显示 “增加”、“删除” 按钮,0-不显示 1-显示
  );

  public $_fields = array(
    'id'=>array(
      'name'=>'id',//字段名,与数据库的字段对应
      'title'=>'ID',//显示标题
      'type'=>'num',//字段类型:num、string、textarea、datetime、bool、select、radio、checkbox、editor、picture(封面)、file(附件)、
      'remark'=>'',// 备注,相当于配置里的tip
      'is_show'=>3,// 1-始终显示 2-新增显示 3-编辑显示 0-不显示
      'value'=>0,//默认值
    ),
    //下面演示一下 select字段怎么显示 radio、checkbox同理
    'type'=>array(
      'name'=>'type',
      'title'=>'类型',
      'type'=>'select',
      'remark'=>'请选择所属类型',
      'is_show'=>1,
       'extra'=>'0:友情链接,1:合作站点',
      'value'=>0,
      'is_must'=>1,
    ),
  );
}

ok,我最后的效果是这样的:

添加一条数据看看吧:

这里要显示具体类型、显示图片等,需要自定义adminlist.html模板了。关于自定义模板,我们下一篇文章再说。关于钩子,其实就是写一个函数从数据库读取数据,然后在前台需要的地方调用钩子就行。如果需要模板,则在钩子函数里解析模板。钩子调用格式一般:

{:hook("钩子名称"),"[参数]"} 没参数就不写。直接写成这样{:hook("钩子名称")}

到此为止就是用系统默认的模板,一步一步的建立自己的插件,是不是很简单,就像填空题一样,只要按照它的规则填空,就ok了。

以上就是本文的全部内容,希望对大家学习PHP程序设计有所帮助。

您可能感兴趣的文章:

  • Thinkphp和onethink实现微信支付插件

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1119957.htmlTechArticle什么是OneThink oneThink后台添加插件步骤,onethink后台 OneThink 以其便捷的建站、丰富的扩展、灵活的二次开发,以及云服务的支持,为广大个...
Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools