Jump to content

<p>Creating modules and add-ons</p>


Nabeel
  • Controllers

    These are located in /core/modules. The basic format in a URL:

    index.php/pilots

    Maps to:

    /core/modules/pilots/pilots.php

    Additionally,

    index.php/module_name/function_name/

    When no function name is given, it defaults to the index() function. For example:

    class ModuleTest extends CodonModule
    {
    public function index()
    {
    	echo "We are at index";
    }
    
    public function pageone()
    {
    	echo "We are at page one";
    }
    }
    

    Going to:

     index.php/moduletest/pageone

    Would output:

     We are at page one

    This simplifies development

    Passing Variables

    Variables can be passed in several different ways. We'll use two different URLs and functions to demonstrate

     index.php/moduletest/pageone/apple/red
    
    index.php/moduletest/pagetwo?fruit=apple&color=red

    The code:

    class ModuleTest extends CodonModule
    {
    public function pageone($fruit='', $orange='')
    {
    	echo "The fruit is an {$fruit} and the color is {$orange}";
    }
    
    public function pagetwo()
    {
    	echo "The fruit is an {$this->get->fruit} and the color is {$this->get->orange}";
    }
    }

    As you can see, the "pageone" method is cleaner - the function parameters will be the variables after the function name in the URL, in the order they appear in the URL.

    The "pagetwo" method is the more "traditional" way of doing things, but they are essentially the same thing. To access the variables in the query string you use:

    $this->get->[variable name]

Creating modules and add-ons


User Feedback

Recommended Comments

There are no comments to display.



Join the conversation

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

Guest
Add a comment...

×   Pasted as rich text.   Restore formatting

  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.

Loading...

×
×
  • Create New...