Properties

$models

$models : 

Type

$data

$data : 

Type

$screen

$screen : 

Type

$layout

$layout : 

Type

$to_json_method

$to_json_method : 

Type

$to_xml_method

$to_xml_method : 

Type

$called_constructors

$called_constructors : 

Type

$exception_handler

$exception_handler : 

Type

$__classid

$__classid : 

The constructor will be passed a '__classid' option.

Ensure this property is populated with its value.

Type

Methods

__construct()

__construct(  $opts = array()) 

Provide a default __construct() method that can chain a bunch of constructors together.

The list of constructors that will be called, and in what order, is dependent on the existence of a class property called $constructors. If the property exists, and is an array, then it is a list of keys, which expect a method called _construct{$key}_controller() is defined in your class (likely via trait composing.)

If the property does not exist, then we will get a list of all methods matching _construct{word}_controller() and will call them all in whatever order they were defined in.

Parameters

$opts

display()

display(  $opts = array()) 

Display the contents of a screen, typically within a common layout.

We use the $data class member as the array of variables to pass to the template.

Parameters

$opts

send_html()

send_html(String  $screen, Array  $data = Null) 

Sometimes we don't want to display a primary screen with a layout, but instead a sub-screen, with no layout, and using specified data.

Parameters

String $screen

The name of the screen view to use.

Array $data

(Optional) Variables to send to the screen view.

The $data defines the variables that will be made available to the screen view template. If you do not specify a $data array, then the $this->data class member will be used instead.

send_json()

send_json(Mixed  $data, Mixed  $opts = array()) 

Sometimes we want to send JSON data instead of a template.

Parameters

Mixed $data

The data to send (see below)

Mixed $opts

Options, see below.

If the $data is a PHP Array, then it will be processed using the json_encode() function. In this case, there is one recognized option (which is only applicable with PHP 5.4 or higher)

'fancy' If set to True, we will use human readable formatting on the JSON string (aka Pretty Printing.)

If the $data is an Object, then it must have a method as per the $this->to_json_method (default: 'to_json'), which will be called, and passed the $opts as its first parameter.

If the $data is a string, it will be assumed to be a valid JSON string, and will be sent as is.

Anything else will fail and throw an Exception.

send_xml()

send_xml(Mixed  $data, Mixed  $opts = Null) 

Sometimes we want to send XML data instead of a template.

Parameters

Mixed $data

The data to send (see below)

Mixed $opts

Options, used in some cases (see below)

If $data is a string, we assume it's valid XML and pass it through.

If $data is a SimpleXML Element, DOMDocument or DOMElement, we use the native calls of those libraries to convert it to an XML string. One caveat: we assume that DOMElement objects have an ownerDocument, and if they don't, this method will fail.

If the $data is another kind of object, and has a method as per the $this->to_xml_method (default: 'to_xml') then it will be called with the $opts as its first parameter.

Anything else will throw an Exception.

model()

model(Mixed  $modelname = Null, Array  $modelopts = array(), Array  $loadopts = array()) 

Return the requested Model object.

Parameters

Mixed $modelname

If set, must be a string, see below.

Array $modelopts

Options to pass to model, see below.

Array $loadopts

Options specific to this, see below.

If the $model is not specified or is Null, then we assume the model has the same basename as the current controller.

The $modelopts will be added to the parameters used in the class loader (which will in turn be passed to the constructor of the Model class.)

If the specified $model has been loaded already by this controller, by default we will return the cached copy, ignoring any new options.

The two $loadopts options we support are:

'forceNew' If set to True, we will always create a new instance of the model, even if we've loaded it before. If caching is on, it will override the previously loaded instance.

'noCache' If set to true, we will not cache the model instance loaded by this call.

name()

name() 

Return our controller base name.

has_upload()

has_upload(String  $fieldname) 

Do we have an uploaded file?

Uses the Nano4\File::hasUpload() static method.

Parameters

String $fieldname

The upload field to look for.

get_upload()

get_upload(String  $fieldname) 

Get an uploaded file. It will return Null if the upload does not exist.

Uses the Nano4\File::getUpload() static method.

Parameters

String $fieldname

The upload field to get.

redirect()

redirect(String  $url, \Nano4\Controllers\Opts  $opts = array()) 

Redirect to a URL.

Parameters

String $url

The URL to redirect to.

\Nano4\Controllers\Opts $opts

Options to pass to Nano4\Plugins\URL::redirect().

go()

go(  $page,   $params = array(),   $opts = array()) 

Go to a route.

This will throw an Exception if the route does not exist.

Parameters

$page
$params
$opts

get_uri()

get_uri(  $page,   $params = array()) 

Get a route URI.

variables, and once again, can only be used with no parameters.

Parameters

$page
$params

url()

url(  $ssl = Null,   $port = Null) 

Return our site URL. See Nano4\Plugins\URL::site_url() for details.

Parameters

$ssl
$port

request_uri()

request_uri() 

Return our request URI. See Nano4\Plugins\URL::request_uri() for details.

current_url()

current_url() 

Return our current URL. See Nano4\Plugins\URL::current_url() for details.

download()

download(  $file,   $opts = array()) 

Send a file download to the client's browser.

Ends the current PHP process.

See Nano4\Plugins\URL::download() for details.

Parameters

$file
$opts

is_post()

is_post() 

Is the server using a POST request?

class_id()

class_id() 

handle_dispatch()

handle_dispatch() 

needs()

needs(  $constructor,   $opts = array(),   $fullname = False) 

Parameters

$constructor
$opts
$fullname

get_prop()

get_prop(  $property,   $default = Null) 

Parameters

$property
$default

set_prop()

set_prop(  $property,   $value) 

Parameters

$property
$value

addWrapper()

addWrapper(String  $method, String  $varname = Null, Bool  $closure = False) 

Add a wrapper to a controller method that you can call from a view template (as a Callable.)

Parameters

String $method

The method we want to wrap into a closure.

String $varname

(Optional) The name of the callable for the views.

Bool $closure

(Default False) If true, use a closure.

If $varname is not specified, it will be the same as the $method.

As an example, a call of $this->addWrapper('url'); will create a callable called $url, that when called, will make a call to $this->url() with the specified parameters.