NanoFramework 1.4.0
A tiny PHP Framework
Public Member Functions | Protected Member Functions | Protected Attributes
Controller Class Reference

Handles I/O and HTTP methods. More...

Public Member Functions

 __construct ()
 

Protected Member Functions

 fragment (string $page)
 
 render ()
 
 getMethod ()
 
 isPost ()
 
 isGet ()
 
 isAjax ()
 
 getPost (?string $element=null)
 
 getGet (?string $element=null)
 
 redirect (string $location)
 
 show404 (?string $message=null)
 

Protected Attributes

 $data = []
 
 $rawData = []
 

Detailed Description

Handles I/O and HTTP methods.

This class must be inherited by all the controllers placed in app/Controllers, directly or indirectly. It provides the options to interact with the user as methods of input/output.

Definition at line 12 of file Controller.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Default constructor, only present to allow specialized class to use theirs.

Definition at line 27 of file Controller.php.

Member Function Documentation

◆ fragment()

fragment ( string  $page)
protected

This method sends the data contained in $data and $rawData to the View and returns the formatted page located at $page.

Parameters
string$pageThe location of the page to parse, relative to APPPATH/Views. The ".html" can be ommited.
Returns
string A string containing the parsed HTML page

Definition at line 38 of file Controller.php.

◆ getGet()

getGet ( ?string  $element = null)
protected

This method returns an element located in the "get" body of the request or the whole body.

If the $element parameter is provided, it returns the value at the given index or null if it doesn't exist.

If no parameters are provided, it returns an associative array of all the values in the body or null if the "get" part of the URL doesn't exist.

Parameters
null | string$elementthe index of the value to retrieve or nothing to retrieve all the values
Returns
mixed Either an element or an associative array

Definition at line 139 of file Controller.php.

◆ getMethod()

getMethod ( )
protected

This method returns a string containing the name of the HTTP method used for the request.

Returns
string "get" or "post", possibly "put" or "delete"

Definition at line 73 of file Controller.php.

◆ getPost()

getPost ( ?string  $element = null)
protected

This method returns an element located in the "post" body of the request or the whole body.

If the $element parameter is provided, it returns the value at the given index or null if it doesn't exist.

If no parameters are provided, it returns an associative array of all the values in the body or null if the HTTP method isn't "post".

Parameters
null | string$elementthe index of the value to retrieve or nothing to retrieve all the values
Returns
mixed Either an element or an associative array

Definition at line 119 of file Controller.php.

◆ isAjax()

isAjax ( )
protected

This method returns a boolean representing if the request has been made through with AJAX.

Returns
bool if the request uses AJAX

Definition at line 103 of file Controller.php.

◆ isGet()

isGet ( )
protected

This method returns a boolean representing if the request has been made with the "get" HTTP method.

Returns
bool if the HTTP method is "get"

Definition at line 93 of file Controller.php.

◆ isPost()

isPost ( )
protected

This method returns a boolean representing if the request has been made with the "post" HTTP method.

Returns
bool if the HTTP method is "post"

Definition at line 83 of file Controller.php.

◆ redirect()

redirect ( string  $location)
protected

This method throws a RedirectException that will be caught by Route::display in order to redirect the page.

Parameters
string$locationthe URI where to redirect the page
Exceptions
RedirectExceptionto bubble the information to Route::display

Definition at line 155 of file Controller.php.

◆ render()

render ( )
protected

This method sends the data contained in $data and $rawData to the View and displays the formatted page located at the page corresponding to the Controller method after having it inserted in APPPATH/Views/template.html. For instance, using $this->render() in the controller method Article::show() will fetch the page located in APPPATH/Views/article/show.html.

Definition at line 51 of file Controller.php.

◆ show404()

show404 ( ?string  $message = null)
protected

This method displays a 404 message to the user.

Parameters
null | string$messageThe message to display

Definition at line 165 of file Controller.php.

Field Documentation

◆ $data

$data = []
protected

All the protected (escaped) data to send to the View.

Definition at line 17 of file Controller.php.

◆ $rawData

$rawData = []
protected

All the unprotected (unescaped) data to send to the View.

Definition at line 22 of file Controller.php.


The documentation for this class was generated from the following file: