Skip to content
Waldo Malqui edited this page Mar 7, 2019 · 11 revisions

Create a route with respond($method, $route, $callback) or respond($route, $callback) where callback is function ($request, $response)

Below is a list of the public methods in the common classes you will most likely use.

For a more formal source of class/method documentation, please see the PHPdoc generated documentation.

$request methods:

Method Description
header($key) Gets a request header
cookie($key) Gets a cookie from the request
session($key) Gets a session variable
param($key, $default = null) Gets a request parameter (get, post, named)
params() Return all parameters
params($mask = null) Return all parameters that match the mask array - extract() friendly
validate($param, $err_msg = null) Starts a validator chain
method() Gets the request method
method($method) Checks if the request method is $method, i.e. method('post') => true
isSecure($required = false) https? Redirect if $required is true and the request is not secure
id() Gets a unique ID for the request
ip() Get the request IP
userAgent() Get the request user agent
uri() Get the request URI
Gets a request parameter

$response methods:

Method Description
header($key, $value = null) Sets a response header
cookie($key, $value = null, $expiry = null) Sets a cookie
cookie($key, null) Removes a cookie
flash($msg, $type = 'info', $params = array() Sets a flash message
file($file, $filename = null) Send a file
json($object, $callback = null) Send an object as JSON(p)
markdown($str, $args, ...) Return a string formatted with markdown
code($code) Sends an HTTP response code
redirect($url, $code = 302) Redirect to the specified URL
refresh() Redirect to the current URL
back() Redirect to the referer
render($view, $data = array()) Renders a view or partial (NOTE: in the scope of $response)
layout($layout) Sets the view layout
yieldView() Call inside the layout to render the view content
onError($callback) $callback takes ($response, $msg, $err_type = null)
set($key, $value = null)
set($arr) Set a view property or helper
escape($str) Escapes a string
query($key, $value = null)
query($arr) Modify the current query string
param($param, $default = null) Gets an escaped request parameter
flashes($type = null) Retrieves and clears all flashes of $type (or all flash messages)
flush() Flush all open output buffers
discard() Discard all open output buffers
buffer() Return the contents of the output buffer as a string
dump($obj) Dump an object
chunk($str = null) Enable response chunking (see the wiki)
($arg1, ...) Calls a user-defined helper
Gets a user-defined property

$validator methods

Method Description
notNull() The string must not be null
isLen($length) The string must be the exact length
isLen($min, $max) The string must be between $min and $max length (inclusive)
isInt() Checks for a valid integer
isFloat() Checks for a valid float/decimal
isEmail() Checks for a valid email
isUrl() Checks for a valid URL
isIp() Checks for a valid IP
isAlpha() Checks for a-z (case insensitive)
isAlnum() Checks for alphanumeric characters
contains($needle) Checks if the string contains $needle
isChars($chars) Validates against a character list
isRegex($pattern, $modifiers = '')
notRegex($pattern, $modifiers ='') Validates against a regular expression
is() Validate against a custom validator
not() The validator can't match
() Alias for is()
Clone this wiki locally