| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Creating your own Plugins

Page history last edited by emolasses 15 years, 5 months ago

 

As mentioned earlier, there are no limitations to what a  plugin is, or is capable of. Take for example the SessionData plugin. It takes a parameter, and based on that, it populates a hidden field with that data from the session. Another, more complex example, is the ManyToMany plugin. Notice how in the bundled examples, the ManyToMany plugin does not correlate to a field in the database. Finally, the Image and File plugins upload and delete files accordingly.

 

For example, say you want to create a new plugin called ColorPicker. The first step would be to create a new file called colorpicker.php in your Plugins directory (codex/application/plugins/). Here is the basic interface of a plugin: 

 

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

 

    class ColorPicker extends codexForms

    {

        function ColorPicker($name,$params) { 

            codexForms::initiate($name,$params);

        }

 

        function getHTML(){

 

        }

}

 

?>

 

The constructor initiates the parameters that are associated with that plugin, and the getHTML() returns the HTML associated with that plugin (to be printed in the form).

 

As mentioned earlier, there are various hooks and callbacks that get called on all the plugins automatically, you have the option of overloading these should your plugin require it.

 

You can access all the form field values in a post insert or post edit hook, through the $_POST array.

 

Within your plugin, you can access the id of the table that the controller is operating on with the following:

$CI = &get_instance();           

$id = $CI->codexadmin->active_id;

 

preInsertHook()

This hook gets called before an element is to be inserted to the database.

 

postInsertHook()

This hook gets called after a record is inserted to the database.

 

preEditHook()

This hook gets called before a record will be updated.

 

postEditHook()

This hook gets called after a record is updated. 

 

prepForDisplay($value)

  • Given the raw $value from the database, this function will "prep" it for display. This means that it should be filtered to prevent XSS attacks.
  • The value returned will be shown in the overview list value for that plugin's field
  • You can access the id the record that is currently being operated on using: $this->codexadmin->active_id

 

prepForDb($value)

Given the raw $value from the form, this function will "prep" it for the database. This means that it should be filtered to prevent SQL injection attacks.

 

prepForDelete($value) 

  • Given the raw $value from the database, this function will "prep" it for deletion. 
  • When an item is deleted from the overview list, the prepForDelete functions for each plugin, if they exist, will be called one by one.
  • You can access the id of the first table codex has deleted from with the following: $CI = &get_instance(); $id = $CI->codexadmin->active_id;

 

prepForDisplay($field, $value)

  • Similar to the previous prepForDisplay, this method gets passed two parameters if its getFieldName() returns an array. This comes out most obviously in the FieldSet plugin where it wraps around a set of plugins and needs to know which $field is getting prepped for the display.
  • Return NULL from prepForDb or prepForDisplay and CE will not process that data into the db

 

prepForDb($field, $value)

  • See prepForDisplay($field,$value).
  • Return NULL from prepForDb or prepForDisplay and CE will not process that data into the db

 

prepForDelete($field, $value)

See prepForDisplay($field,$value).

 

getFieldName()

  • Returns the name of the field(s) in the table associated with that field.
  • If it's a field that doesn't exist in the database, you can stop code extinguisher from looking it up by returning NULL

 

getDisplayName()

Returns the name that is displayed in the header row of the Overview page.

 

getQueryName()

If the plugin pulls data from other tables, then this function returns the tablename.fieldname of that plugin.

 

getDbTable()

Returns the name of the table associated with the plugin.

 

 

Comments (0)

You don't have permission to comment on this page.