Developers

Code Walkthrough

This section provides a walkthrough of some of the code. In this example we're looking at the checklist which appears when first visiting the admin area after installing the application.

Controller

/backend/controller/main/checklist.php

                            <?php
                            namespace Commentics; // this ensures the class name won't conflict
                             
                            class MainChecklistController extends Controller // extends the parent class in /system/engine/
                            {
                                public function index()
                                {
    						        $this->loadLanguage('main/checklist'); // loads the corresponding language
                             
    						        $this->loadModel('main/checklist'); // loads the corresponding model
                             
    						        if ($this->request->server['REQUEST_METHOD'] == 'POST') { // if the form is posted
    						            if ($this->validate()) { // calls a private method we've ommited for simplification
    						                $this->model_main_checklist->update(); // calls the model method to update a setting
                             
    						                $this->response->redirect('main/dashboard'); // redirects the user to the dashboard
                                        }
                                    }
                             
    						        $this->components = array('common/header', 'common/footer'); // loads the header and footer
                             
    						        $this->loadView('main/checklist'); // loads the corresponding view
                                }
                            } // we end the file with an empty line below
                             
    					
Model

/backend/model/main/checklist.php

                            <?php
                            namespace Commentics; // this ensures the class name won't conflict
                             
                            class MainChecklistModel extends Model // extends the parent class in /system/engine/
                            {
                                public function update() // the method called by the controller above
                                {
                                    // update the database setting to set that the checklist is complete
    						        $this->db->query("UPDATE `" . CMTX_DB_PREFIX . "settings` SET `value` = '1' WHERE `title` = 'checklist_complete'");
                                }
                            } // we end the file with an empty line below
                             
    					
View

/backend/view/default/template/main/checklist.tpl

                            <?php echo $header; ?>
                             
                            <div id="main_checklist_page">
                             
                                <div class='page_help_block'><?php echo $page_help_link; ?></div>
                             
                                <h1><?php echo $lang_heading; ?></h1>
                             
                                <hr>
                             
                                <?php if ($success) { ?>
                                    <div class="success"><?php echo $success; ?></div>
                                <?php } ?>
                             
                                <?php if ($info) { ?>
                                    <div class="info"><?php echo $info; ?></div>
                                <?php } ?>
                             
                                <?php if ($error) { ?>
                                    <div class="error"><?php echo $error; ?></div>
                                <?php } ?>
                             
                                <?php if ($warning) { ?>
                                    <div class="warning"><?php echo $warning; ?></div>
                                <?php } ?>
                             
                                <p><?php echo $lang_text_welcome; ?></p>
                             
                                <ul>
                                    <li><?php echo $lang_text_permissions; ?></li>
                                    <li><?php echo $lang_text_email; ?></li>
                                    <li><?php echo $lang_text_fields; ?></li>
                                    <li><?php echo $lang_text_approval; ?></li>
                                </ul>
                             
                                <p><?php echo $lang_text_integrate; ?></p>
                             
                                <p><?php echo $lang_text_return; ?></p>
                             
                                <form action="index.php?route=main/checklist" class="controls" method="post">
                                     <input type="hidden" name="csrf_key" value="<?php echo $csrf_key; ?>">
                             
                                     <p><input type="submit" class="button" value="<?php echo $lang_button_completed; ?>" title="<?php echo $lang_button_completed; ?>"></p>
                                </form>
                             
                            </div>
                             
                            <?php echo $footer; ?>