Jump to content
Sign in to follow this  
Hedge

Plugin Tutorial

Recommended Posts

Installing a Plugin -

1. If your plugin is zipped, unzip it.

2. Place the plugin into the plugin folder. root > application > plugin > HERE

3. Open your database and run any SQL queries that came with the plugin. Delete these from the plugin once completed.

Thats it! the plugin is installed.

At this stage its best to check if the plugin author has left any other instructions. There maybe settings which need changed before you run it for the first time.

Important Information:

* You cannot have two plugins with the same name. If you try to add a plugin with the same name as one already installed, the old one will be over written. So remove the old before you add the new.

Creating a Plugin -

I suggest you use the official Ullr Crime plugin as a base for any new plugin you want to create. All the file structure is already setup for you and the code is heavily commented so you know what each thing does.

1. Create the basic file structure. (if not using another plugin to copy over)

For the following xxx will represent the plugin name. Everything must be in lowercase.

 

   xxx >
       controller >
           xxx.php
       model >
           xxxmodel.php
       view >
           index.php
       information.txt

 

2. Create the controller, this is the xxx.php file in the controller folder.

 

<?php
class Xxx extends Controller 
{
   function __construct() 
   {
       parent::__construct();
       if ($this->UserModel->is_logged_in() != true) {header('Location:'.URL.'home');exit();} 
   }

   public function index() 
   {
       require HEADER; 
       require PLUGIN . 'xxx/view/index.php'; 
       require FOOTER; 
   }
}
?>

 

This is very basic example of a plugin. This will first check that a user is logged in, if not they are directed to the external homepage. If they are logged in they will be shown the main page of the plugin. The display part of the plugin is called the view.

3. Create the model.

 

<?php
class XxxModel
{
   function __construct($db)
   {
       try {
           $this->db = $db;
       } catch (PDOException $e) {
           exit('Database connection could not be established.');
       }
   }
}
?>

 

The model links the plugin to the database. All database interactions take place in this file. As our controller is only going to display HTML, this model is empty.

4. Create the view.

 

<div class="row">
   <div class="col-md-4 col-sm-4 col-xs-6">
        <h1>Hey! im a Plugin.</h1>
   </div>
</div>

 

The header and footer has been called in the controller, so we only need to show things directly about the plugin itself.

5. Create the information.txt file. This file explains what the plugin is and who made it.

 

/------------------/
PLUGIN INFORMATION

PLUGIN NAME:     Xxx
DESCRIPTION:     Displays a message.
AUTHOR:            Ullr
VERSION:        V1.0
DATE CREATED:    22 Feb 2016
DATE UPDATED:    No Updates Yet
PAYMENT:        Free
/------------------/
UPDATE / CHANGE LOG

No updates yet
/------------------/

 

So Now you have a basic plugin created. Time to add some depth to it and create something awesome. Use the demo/crime plugin to help you out.

Helpful Information:

To access a model fucntion, use the following -

 

$this->XxxModel->function_name();

 

Note: You cannot access other plugin models.

 

Important Information:

* The name you choose for you plugin must stay the same throughout the entire plugin.

* All file names need to be in lowercase.

* Controller class name needs to have a capital first leter.

* The first function in your controller needs to be 'index', any others can be named anything.

* Model class name needs to have a capital first letter with 'Model' joined to the end.

* The Model functions can be named anything you like.

 

I will improve these instructions when and where ever possiable. Feel free to comment helpful additions as you get to grips with the engine.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...