Writing the installer

We will be needed a database table to store our notes. Let's write a script which will be called when the plugin install button is clicked. Create a file with name install.php in the notes directory with following contents-

<?php
$table = new Schema('app_notes'); # app_notes is the table name which will be created automatically when installing
$table->add('title','varchar', 200);
$table->add('contents','text');
$table->add('created_at','TIMESTAMP','','null');
$table->add('updated_at','TIMESTAMP','','null');
$table->save();

In this file we are telling to create a database table named app_notes with title, contents etc. columns. The concept is this file will be called when the plugin is installing, you can write any php code here. For instance, if you do not want to use the Schema class, you can also write traditional sql queries here using ORM::execute('your sql code to create tables here');

after installing the plugin, in phpmyadmin or any other dba tool, it will look like this-

What you have learned

  • You will add a file with name install.php in the plugin directory and you will write the codes to perform actions when plugins are installed.
  • To create database table you can use built in Schema class or you can write your own php code to add database table.
By continuing to use this site you consent to the use of cookies in accordance with our Cookie policy. close notification