-
Notifications
You must be signed in to change notification settings - Fork 0
Getting started with controllers
You may create controllers in your /app/controllers folder. Each controller has to contain the following template:
<?php
/*
* Codengine
* FilePath: app/controllers/name.controller.php
*/
class controller_name
{
public function __construct($params)
{
$registry = Registry::getInstance();
foreach (reset($registry) as $key => $value) { $this->{$key} = $value; }
}
public function action_index()
{
}
}
?>
The first function your webpage will call is going to be action_index(). You may use the View class static functions to load views:
View::forge('welcome/index', $data);
This will call the file /app/views/welcome/index.php file. The first parameter will be the desired view file. The 2nd parameter is an array which will pass into that view, like the page title. You may also add a 3rd parameter to specify whether the page will load the default header and footer template (default true, you can set it to false).
You may use other View static functions:
- error($str) - to print a bootstrap error alert block. The $str will be the content of the alert. Title is static and set to 'An error occurred'. You can change this value at /app/base/View/View.base.php file on line 29.
- success($str) - to print a bootstrap success alert block. The $str will be the content of the alert. Title is static and set to 'Success!'. You can change this value at /app/base/View/View.base.php file on line 42. After printing the alert block the page will refresh in 3 seconds through a meta refresh tag.
- display_menu() - to print a menu (ul>li>a[href="something"]>Something) of your controllers. Alternatively, you may pass a parameter 'array' to the function and get an array of all pages as a result.
To get a post value securely (to prevent XSS attacks), use the following function:
$this->sec->_('key');
You may use other security functions:
- password($str) - to generate an encrypted password (PLEASE MAKE SURE TO ENTER A RANDOM STRING OF YOUR OWN ON FILE 'app/base/Security/Security.base.php' on line 9).
- generate_session($array) - to create a session. Please insert an array which will contain the session name and value.
- destroy_session($array) - to destroy a session. Please insert an array which will contain the session name.
- validate($string, $mode) - to validate a string. The mode could be one of the following: email, int, phone, ip, url.
To check in which page the user is currently on, use the $this->param array which contains the user's location on the system. For example, $this->params[1]
.
Happy coding 👍