What is onethink onethink background add plugin step _php tips

Source: Internet
Author: User
Tags add time comments learn php learn php programming php programming

Onethink with its convenient construction station, rich expansion, flexible two times development, as well as the support of cloud services, for the vast number of individuals and enterprises to create a new opportunity and opportunity, will become the Internet new people.

Onethink Characteristics Introduction:

1. Based on the latest version of Thinkphp Thinkphp3.2.

2. Modularity: A new architecture and modular development mechanism for flexible expansion and two development.

3. Document model/Classification system: through and document model binding, as well as different types of documents, different classifications can achieve the function of differentiation, easy to implement such as information, downloads, discussions and pictures and other functions.

4. Open source free: Onethink Follow Apache2 Open source agreement, free to use.

5. User behavior: Support custom user behavior, can record and share the behavior of individual user or group user, provide valid reference data for your operation decision.

6. Cloud deployment: Through the drive to easily support the deployment of the platform, so that your site seamless migration, built-in already support SAE.

7. Cloud services Support: To start supporting cloud storage, cloud security, cloud filtering and cloud statistics services, more intimate services to make your site more secure.

8. Security and robustness: Provide a robust security strategy, including backup recovery, fault tolerance, prevent malicious attack login, Web page tamper-proof and other security management functions, to ensure the system safe, reliable and stable operation.

9. Application Warehouse: The official application Warehouse has a large number of Third-party plug-ins and application modules, template themes, a number of contributions from the open source community, so that your site "one" beautiful.

Onethink background Add plug-in step:

Version: V1.1.141212 (note: v1.1 also have many versions, accidentally down to V1.1.140202, there are other versions, recommend to the code hosting platform to download the latest version)

I am not lazy, take every step of the steps are recorded.

First, enter the background, create Plug-ins

Here's the hook I created a indexfooter, because I just need to show the link at the bottom of the front page. We put all the above to tick on the hook, as to what the difference, we can build a few examples of their own to distinguish between the resulting file is the same. Ok! Here is our Friendship link plugin to create a good! Click "OK". (Here's a custom template or whatever, and I'll show you the effects of adding a custom template in the next article)

Second, click on "Installation" can be found, we just installed the links plugin, click "Settings", you will see it has a default "whether to open random" option, here we ignore it, because we do not use, and so on to delete. After installation, we can navigate to the left side of the "installed plugin background" See our new "Friendship link"

Third, when we click on the left-hand side of the navigation "Friendship link", you will find that the error, is probably said that a table does not exist. Yes, we just built the plugin, if it involves data storage to the database, you need to build the table. This does not go directly to the database to build, because it is very impersonal. Then we will find the function of installing plug-ins, when installing the plug-in database, so good. First, the system's plug-ins are all stored under the root directory/addons/folder, open this folder, we see a links folder, this is the plug-in we just created, a plug-in corresponding to a folder. Open the Links folder, which has 2 files and 2 folders.

Four, in fact now Onethink do more and more concise, do not know the PHP people to create plug-ins, and then you will find. Of course, if you have your own ideas, do not want to limit the official restrictions, it is still to learn PHP.

V. Open the plugin entry file: LinksAddon.class.php There is a class Linksaddon, first to analyze this file

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

Public Function Install () {//Install plug-in method//1, add datasheet $model = D ();
    $db _prefix = C (' Db_prefix ');
    
    $table _name = "{$db _prefix}links"; $sql =<<<sql CREATE TABLE IF not EXISTS ' $table _name ' (' id ' int (one) unsigned not NULL auto_increment ' primary key ', ' title ' varchar NOT NULL default ' COMMENT ' site name ', ' link ' varchar (140) NOT null default ' COMMENT ' link address ', ' Sum Mary ' varchar (255) NOT null default ' COMMENT ' site description ', ' mailto ' varchar (MB) NOT null default ' COMMENT ' webmaster contact ', ' sort ' Int (3) unsigned NOT NULL default 0 COMMENT ' priority ', ' nofollow ' tinyint (1) unsigned NOT NULL default 0 COMMENT ' tracking ', ' t Ype ' tinyint (3) unsigned NOT NULL default 1 COMMENT ' type grouping ', ' cover_id ' int (one) unsigned NOT null default 0 COMMENT ' cover picture ' , ' status ' tinyint (2) NOT NULL default 1 COMMENT ' state (0: Disabled, 1: normal) ', ' create_time ' int (one) unsigned NOT null default 0 COMM ENT ' Add time ', PRIMARY KEY (' id ') engine=myisam auto_increment=4 DEFAULT Charset=utf8 row_format=dynamic ' friendshipConnection table ';
  
    SQL;
  $model-> Execute ($sql);//Execute SQL statement//2, return True to indicate that the plug-in installation was successfully returned true; }

I have omitted a lot of details here to judge, we are perfect.

Six, since the installation of Plug-ins, the new table, we uninstall the plugin will be the time to delete the table, or the next time you install the plugin will be a problem. So we uninstall the method code as follows:

Public Function Uninstall () {//Uninstall plug-in method
      $model = D ();
      $db _prefix = C (' Db_prefix ');
      $table _name = "{$db _prefix}links";
      $sql = "DROP TABLE IF EXISTS '". $table _name. " `;";
      $model-> Execute ($sql);//Execute SQL statement return  
      
      true;
    }

OK, here is almost, save the LinksAddon.class.php file, should be able to display the normal, we look. Go to the list of plugins, uninstall the links plugin, and then reinstall it. Click on the left menu "Friendship link", you can see

The reason that this list is displayed normally is because the system has a default template, and in the \application\admin\view\addons folder, interested students can study these template files, The template of this list is adminlist.html, then we want to put the cover, title, description and so on these words to get rid of, to go to the template to change it? Careful classmate estimated that, in the $admin_list array of LinksAddon.class.php file configuration, the other look at the following comments on the understanding, here in detail about the List_grid associated with the array. The links datasheet We just created has fields such as ID, title, link, and so on, you can add any fields you want to display in this list. My code here is as follows:

The ' List_grid ' =>array (     //) defines the function and link
        ' title: Site name ',
        ' link: link ', ' The table header and the model as shown in the table outside the ID number.
        Summary: Description ',
        ' Create_time|time_format: Add Time ',//time_format is a function that formats the time, other places want to use what functions can also be written in this format
        ' ID: action: [ edit]| edit, [delete]| delete '
      ),

Save, refresh background Links list

We click on "Add" to add a link bar, you will find that only a book name section. Let's open the model/linksmodel.class.php file and I'll explain the two self-contained arrays here, and look at the comments in the code below.

 class Linksmodel extends model{public $model = Array (' title ' => '),/Add [title], edit [title]
    , delete [title] hint ' template_add ' => ',//custom new template custom HTML edit.html will read the plugin root template ' template_edit ' => ',//custom Edit Template HTML

  ' Search_key ' => ',//search field name, default is title ' Extend ' =>1,//////In the background list whether to show "add", "delete" button, 0-Do not show 1-show); Public $_fields = array (' ID ' =>array (' name ' => ' id ',//field name, corresponding to database field ' title ' => ' ID ',//display title ' Ty PE ' => ' num ',//field type: num, String, TEXTAREA, datetime, BOOL, select, Radio, CheckBox, editor, Picture (cover), file (attachment), ' Remark ' => ',//remark, equivalent to the tip ' is_show ' =>3,//1-Always show 2-new show 3-edit display 0-do not show ' value ' =>0,//default value /The following shows how the Select field shows Radio, checkbox the same ' type ' =>array (' name ' => ' type ', ' title ' => ' Types ', ' type ' = > ' select ', ' remark ' => ' Please select the type ', ' is_show ' =>1, ' extra ' => ' 0: Links, 1: Cooperative sites ', ' value ' =>0
, ' Is_must ' =>1,),); }

OK, my final effect is this:

Add a piece of data to see:

Here to display specific types, display pictures, etc., you need to customize the adminlist.html template. For a custom template, we'll talk about the next article. The hook, in fact, is to write a function to read data from the database, and then call the hook at the front of the line where needed. If a template is required, the template is parsed in the hook function. Hook Call format General:

{: Hook ("Hook name"), "[Parameters]"} does not write without parameters. Directly written like this {: Hook ("Hook name")}

The end is to use the system default template, step-by-step to establish their own plug-ins, is not very simple, like the fill in the blanks, as long as the rules in accordance with its fill in the blanks, OK.

The above is the entire content of this article, I hope that you learn PHP programming help.

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.