What is the OneThinkoneThink background plugin adding step, onethink background _ PHP Tutorial

Source: Internet
Author: User
Tags add time learn php programming
What is the OneThinkoneThink background plugin adding step, onethink background. What is the OneThinkoneThink background plugin adding step, onethink background OneThink with its convenient site establishment, rich expansion, flexible secondary development, and cloud service support, add plug-in steps for the OneThink oneThink background.

OneThinkWith its convenient website construction, rich expansion, flexible secondary development, and cloud service support, the website construction for individuals and enterprises brings new opportunities and opportunities, it is about to become a new internet trend.

OneThink features:

1. based on ThinkPHP's latest version Thinkphp3.2.

2. modularization: The new architecture and modular development mechanism facilitate flexible expansion and secondary development.

3. document model/classification system: by binding to document models and different document types, different categories can implement differentiated functions, such as information, downloads, discussions, and images.

4. free Open Source: OneThink complies with the Apache2 open source protocol and is free to use.

5. user behavior: supports user-defined behaviors. you can record and share behaviors of individual users or group users to provide effective reference data for your operation decisions.

6. cloud deployment: with the driver, you can easily support platform deployment, so that your website can be seamlessly migrated, with built-in support for SAE.

7. cloud service support: Cloud storage, cloud security, cloud filtering, and cloud statistics services will be launched soon. more considerate services will make your website feel at ease.

8. secure and stable: provides robust security policies, including backup recovery, fault tolerance, malicious attack logon prevention, and webpage tamper-proofing. This ensures the system runs securely, reliably, and stably.

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, making your website "One" beautiful.

To add a plug-in to the oneThink background:

Version: V1.1.141212)

I am not lazy and keep records of every step.

1. go to the background and create a plug-in

I created an indexFooter for the hook here, because I only need to display the link at the bottom of the front-end homepage. We have checked all the above items. as to the differences, you can create several examples to identify whether the generated files are the same. OK! Here, our friendship link plug-in has been created! Click "OK ". (If you do not enter a custom template or something here, I will demonstrate the effect of adding a custom template in the next article)

2. click "install". find the newly installed Links plug-in and click "set". you will see that it has the default "enable random" option, we don't care about it here, because we can't use it, and we will delete it later. After the plug-in is installed, you can see the new "link" in the left-side navigation bar "installed plug-in background"

3. when we click "link" in the left-side navigation bar, you will find an error, which means that a table does not exist. Yes. we just created a plug-in. if data is stored in the database, you need to create a table. The database is not directly built here, because it is very unfriendly to do so. Then we can find the function for installing the plug-in and create a database when installing the plug-in. First, all the system plug-ins are stored in the root directory/Addons/Folder. open this folder and we can see a Links folder. this is the plug-in we just created. a plug-in corresponds to a folder. Open the Links folder, which contains 2 files and 2 folders.

4. now oneThink is more and more concise. people who do not understand PHP can create plug-ins, and you will find out later. Of course, if you have your own ideas and don't want to limit them to official restrictions, you should learn php well.

5. open the plug-in entry File: LinksAddon. class. php contains a LinksAddon class. let's analyze this file first.

Here, I changed the model value of the $ admin_list array to links to correspond to the plug-in. Next, add the statement for creating a database in the install method, so that we will create a new database when installing the plug-in. my code is as follows:

Public function install () {// method for installing the plug-in // 1. add the data table $ model = D (); $ db_prefix = C ('Db _ prefix '); $ table_name = "{$ db_prefix} links"; $ SQL = <
 
  
Execute ($ SQL); // execute the SQL statement // 2. return true, indicating that the plug-in is successfully installed and return true ;}
 

I have omitted a lot of details and made them perfect.

6. since a new table is created when the plug-in is installed, we need to delete the table when uninstalling the plug-in. otherwise, problems may occur when the plug-in is installed next time. Therefore, the uninstall method code is as follows:

Public function uninstall () {// method for uninstalling the plug-in $ model = D (); $ db_prefix = C ('Db _ prefix '); $ table_name = "{$ db_prefix} links"; $ SQL = "DROP TABLE IF exists '". $ table_name. "';"; $ model-> execute ($ SQL); // execute the SQL statement return true ;}

Okay, it's almost done here. Save the LinksAddon. class. php file and it should be displayed normally. let's take a look. Go to the plug-in list, uninstall the Links plug-in, and then reinstall it. Click "link" in the left-side menu.

The reason why the list can be displayed is that the system has a default template. in the \ Application \ Admin \ View \ Addons folder, interested templates can be used to study these template files. In this example, the template adminlist.html should be replaced, do you want to modify it in the template? Careful students may have noticed that the $ admin_list array in the LinksAddon. class. php file is configured. others can see the annotations below. here we will detail the arrays associated with list_grid. The links data table we just created has fields such as id, title, and link. you can add any fields in this list. The code here is as follows:

'List _ grid' => array (// Here, the header name and model displayed in the table except the id serial number are the same as those in the table. function and link 'Title: website name' are supported ', 'link: link', 'Summary: description', 'create _ time | time_format: add time', // time_format is a function that formats the time, you can also write 'Id: Operation: [EDIT] | EDIT, [DELETE] | delete' for any function you want to use elsewhere '),

Save and refresh the list of background links

Click "add" to add a link. you will find that there is only one name field. Open the Model/LinksModel. class. php file. here I will explain the two built-in arrays separately. for details, refer to the comments in the code below.

Class LinksModel extends Model {public $ model = array ('title' => '', // added the 'Template _ add' => ''prompt for [title], edit [title], and delete [title '', // custom new template custom html edit.html will read the template 'Template _ edit' => ''in the plug-in root directory '', // custom editing Template html 'search _ key' => '', // field name for search. the default value is title 'extend' => 1, // check whether the "add" or "delete" buttons are displayed in the background List. if the value is 0, the value 1 is not displayed ); public $ _ fields = array ('id' => array ('name' => 'id', // field name, corresponds to the database field 'title' => 'id', // displays the title 'type' => 'num', // field type: num, string, textarea, datetime, bool, select, radio, checkbox, editor, picture (cover), file (attachment), 'remark' => '', // remarks, equivalent to tip 'is _ Show' => 3 in the configuration, // 1-always show 2-add show 3-edit show 0-not show 'value' => 0, // default value). // The following example shows how the select field displays radio and checkbox. Similarly, 'type' => array ('name' => 'type ', 'title' => 'type', 'type' => 'select', 'remark' => 'Select the type ', 'Is _ Show' => 1, 'Extra '=> '0: link, 1: Site', 'value' => 0, 'is _ must '=> 1 ,),);}

OK. The final result is as follows:

Add a piece of data:

Here we need to display the specific pictures and images, and customize the adminlist.html template. For more information about custom templates, see the next article. You can write a function to read data from the database, and then call the hook as needed at the front-end. If a template is required, the template is parsed in the hook function. The hook call format is generally:

{: Hook ("hook name"), "[parameter. Directly written as this {: hook ("hook name ")}

By now, the default system template is used to build your own plug-ins step by step. is it very easy, just like filling in blank questions, as long as you fill in the blanks according to its rules, it will be OK.

The above is all the content of this article. I hope it will help you learn PHP programming.

Articles you may be interested in:
  • Thinkphp and onethink implement the payment plug-in

The oneThink background plugin adding step, onethink background OneThink with its convenient site construction, rich expansion, flexible secondary development, and cloud service support, for the majority...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.