Skip to content

Routing system

Keramat Jokar edited this page May 13, 2024 · 1 revision

How do I access my controllers methods?

The routing system we use is very straight forward, see for yourself: example.com/module/controller/function/argument1/argument2
All segments except of the module are optional and can be leaved out in favor of their default values;

Default controller: Name of the module
Default function: index

Arguments are completely optional and will be sent in order to your function.

The controller methods you want to access have to be public, if you don't want them to be accessable from the URL you can make them private

Example of the structure of a basic news module:

<?php

use MX\MX_Controller;

/**
 * News Controller Class
 * @property news_model $news_model news_model Class
 */
class News extends MX_Controller
{
    /**
     * Can be accessed via http://mypage.com/news/
     * or via http://mypage.com/news/news
     */
    public function index()
    {
        // Call our private method
        $this->doSomething();
        
        // Display all news
    }

    /**
     * Can be accessed via http://mypage.com/news/view/123
     * or via http://mypage.com/news/news/view/123
     */
    public function view($id)
    {
        // Display news with ID = $id
    }

    /** 
     * Can't be accessed from the outside
     */
    private function doSomething()
    {
        // Do something privately
    }
}
Clone this wiki locally