# Controllers

We’ll start by creating a controller inside minical-extension-boilerplate->controllers. In this example, there is a variable $module\_name its module name or folder name in this case it's minical-extension-boilerplate. \_Construct(), initialize all the dependencies such as models, libraries, helpers. now moving forward in any controller's method load the JS or CSS file related to that particular section. Here is the detail about how you can add custom data into the database [Broken mention](broken://pages/4n8NvyIW7Yx4OAdH3krh).

{% code title="show\_booking.php" %}

```php
<?php 
class Show_booking extends MY_Controller
{
    public $module_name;
	function __construct()
	{
        parent::__construct();

        $this->module_name = $this->router->fetch_module();
        $this->load->model('../extensions/'.$this->module_name.'/models/Bookings_model');
        $this->load->library('../extensions/'.$this->module_name.'/libraries/GreetingEmail');
     
	}
	
    /**
    * This function will display the list of the last 20 bookings.
    * load the template of the booking page
    */  
    function show_latest_bookings(){

        $data['bookings'] = $this->Bookings_model->get_bookings();
        $files = get_asstes_files($this->module_assets_files, $this->module_name, $this->controller_name, $this->function_name);

        $data['menu_on'] = TRUE;
        $data['selected_menu'] = 'bookings';
        $data['main_content'] = '../extensions/'.$this->module_name.'/views/booking';

        // library function call
        // $this->greetingemail->send_greeting_email();

        // action call
        // do_action('action name', variable);
        // do_action('add.booking.created', $data);  // this is a core action
        // do_action('my-custom-action', $data);   //this is a custom action 

        // filter call
        // apply_filter('filter name', variable);
        // apply_filter('my-custom-action', $data);

        // helpers function call
        // check if funtion exists or not
        // if(function_exists('custom_helper')){
        //   custom_helper($data);
        // }

        $this->template->load('bootstrapped_template', null , $data['main_content'], $data);
    }

    /**
    * This function will display the list of the last 20 customers.
    * load the template of customer page
    */  
    function show_customer_list()
    {
        $data['customers'] = $this->Bookings_model->get_customer_list();
        $files = get_asstes_files($this->module_assets_files, $this->module_name, $this->controller_name, $this->function_name);
        $data['menu_on'] = TRUE;
        $data['main_content'] = '../extensions/'.$this->module_name.'/views/customer_list';
        $this->template->load('bootstrapped_template', null , $data['main_content'], $data);
    } 
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.minical.io/build-an-extension/build-your-first-extension/controllers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
