The Controllers

With Mamuph you can create different set of controllers. A controller is a class responsible of routing the actions and events of your app.

Mamuph provides by default the Main controller that is defined at "App / Controller / Main.php":

    /**
     * Default controller entry-point
     */
    class Controller_Main extends Controller
    {

        /**
         * Entry point
         */
        public function action_main()
        {

            // Add your controller entry code below this line

        }

    }

The Main controller works as entry point for your app, that it means that when your app is executed the first method to call is the method "action_main" from the same controller.

It is possible change the default entry point controller inside the bootstrap.php file

Defining new controllers

If your app is just a simple batch process or is designed for performing just one single operation, it is very probably that you don't require more than one single controller, however if your app require more actions or controllers, your can define them in the following way:

  1. Create a new file inside "App / Controller". The file name should have the first letter in uppercase (capitalized). As example the controller file "makevideo" should be saved as "App/Controller/Makevideo".

  2. The controller class name should have the prefix "Controller_" following with the controller name capitalized (only the first letter), so for example the class "makevideo" should look like "Controller_Makevideo".

  3. The controller class should extends from "Controller".

  4. The controller should have the entry point method "action_main".

If we followed the last 4 steps our new controller should look like this:

    class Controller_Makevideo extends Controller
    {
        public function action_main()
        {
            // Your code goes here
        }
    }

Calling to different controllers

You can call to your new controller "makevideo" from the default entry-point controller (main) in different ways:

  1. Call the controller entry point using the Apprunner::execute() method. Example:

    Apprunner::execute('Makevideo');
  2. Just instance your controller and call to default action (action_main) or another method. Example:

    $subaction = new Controller_Makevideo();
    $subaction->action_main();

Calling to different actions

It is possible to define different actions inside a controller and route them. Example

    class Controller_Makevideo extends Controller
    {
        // Entry point
        public function action_main()
        {
            if (File::exists('video.mp4'))
                $this->action_compress('video.mp4');
        }

        protected function action_compress($params)
        {
            // Compress video here
        }
    }