Table of Contents
What is OneThink oneThink backend add plug-in steps, onethink backend
您可能感兴趣的文章:
Home Backend Development PHP Tutorial What is OneThink? OneThink background adding plug-in steps, onethink background_PHP tutorial

What is OneThink? OneThink background adding plug-in steps, onethink background_PHP tutorial

Jul 12, 2016 am 08:54 AM
plug-in

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;
  }
Copy after login

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;
    }
Copy after login

好了,到这里就差不多了,保存一下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]|删除'
      ),
Copy after login

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

我们点击“新增” 来增加一个友情链接吧,你会发现,只有一个书名字段。我们打开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,
    ),
  );
}
Copy after login

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

添加一条数据看看吧:

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

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

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

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

您可能感兴趣的文章:

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1119957.htmlTechArticle什么是OneThink oneThink后台添加插件步骤,onethink后台 OneThink 以其便捷的建站、丰富的扩展、灵活的二次开发,以及云服务的支持,为广大个...
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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
PyCharm Beginner's Guide: Comprehensive understanding of plug-in installation! PyCharm Beginner's Guide: Comprehensive understanding of plug-in installation! Feb 25, 2024 pm 11:57 PM

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] Error loading plugin in Illustrator [Fixed] Feb 19, 2024 pm 12:00 PM

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

Share three solutions to why Edge browser does not support this plug-in Share three solutions to why Edge browser does not support this plug-in Mar 13, 2024 pm 04:34 PM

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.

What is the Chrome plug-in extension installation directory? What is the Chrome plug-in extension installation directory? Mar 08, 2024 am 08:55 AM

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

How to use a WordPress plugin to implement instant location functionality How to use a WordPress plugin to implement instant location functionality Sep 05, 2023 pm 04:51 PM

How to use WordPress plug-ins to achieve instant location functionality With the popularity of mobile devices, more and more websites are beginning to provide geolocation-based services. In WordPress websites, we can use plug-ins to implement instant positioning functions and provide visitors with services related to their geographical location. 1. Choose the right plug-in. There are many plug-ins that provide geolocation services in the WordPress plug-in library to choose from. Depending on the needs and requirements, choosing the right plug-in is the key to achieving instant positioning functionality. Here are a few

How to use WordPress plug-in to implement video playback function How to use WordPress plug-in to implement video playback function Sep 05, 2023 pm 12:55 PM

How to use WordPress plug-in to implement video playback function 1. Introduction The application of video on websites and blogs is becoming more and more common. In order to provide a high-quality user experience, we can use WordPress plug-ins to implement video playback functions. This article will introduce how to use WordPress plugins to implement video playback functions and provide code examples. 2. Choose plug-ins WordPress has many video playback plug-ins to choose from. When choosing a plug-in, we need to consider the following aspects: Compatibility: Make sure the plug-in

How to add WeChat mini program functionality to WordPress plug-in How to add WeChat mini program functionality to WordPress plug-in Sep 06, 2023 am 09:03 AM

How to Add WeChat Mini Program Functions to WordPress Plugins With the popularity and popularity of WeChat mini programs, more and more websites and applications are beginning to consider integrating them with WeChat mini programs. For websites that use WordPress as their content management system, adding the WeChat applet function can provide users with a more convenient access experience and more functional choices. This article will introduce how to add WeChat mini program functionality to WordPress plug-in. Step 1: Register a WeChat mini program account. First, you need to open the WeChat app

Does PyCharm Community Edition support enough plugins? Does PyCharm Community Edition support enough plugins? Feb 20, 2024 pm 04:42 PM

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

See all articles