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-
install.phpin the plugin directory and you will write the codes to perform actions when plugins are installed.
Schemaclass or you can write your own php code to add database table.