This is the parent class for all controllers in /src/controllers, and indirectly for all controllers
that extend VendorController (which, in turn, extend this).
ParentController is the class that manages assets, paths, $_GET and $_POST, views, etc.
Methods summary
public
|
#
__construct( )
Every Controller that extends ParentController must explicitly
Every Controller that extends ParentController must explicitly
|
public static
Core\ParentController
|
#
singleton( )
Returns a ParentController instance, creating it if it did not exist.
Returns a ParentController instance, creating it if it did not exist.
Returns
|
public
Core\ParentModel
|
#
getModel( )
Returns the instance of the model for this controller
Returns the instance of the model for this controller
Returns
|
public
mixed
|
#
getGet( $key, $fallback = NULL )
Filters an input (GET) variable and returns it. If key doesn't exist or the value equals NULL, returns $fallback
Filters an input (GET) variable and returns it. If key doesn't exist or the value equals NULL, returns $fallback
Returns
mixed $_GET[$key] or $fallback
Var
string $key The key
mixed $fallback if not null, would be taken as the default value. Otw the parameter is required.
|
public
mixed
|
#
getPost( $key, $fallback = NULL )
Filters an input (POST) variable and returns it. If key doesn't exist or the value equals NULL, returns $fallback
Filters an input (POST) variable and returns it. If key doesn't exist or the value equals NULL, returns $fallback
Returns
mixed $_POST[$key] or $fallback
Var
string $key The key
mixed $fallback if not null, would be taken as the default value. Otw the parameter is required.
|
public
|
#
show( string $view, string $template = 'default' )
Shows a view inside a specified template
Remember that both $view and $template can be absolute or relative paths
Shows a view inside a specified template
Remember that both $view and $template can be absolute or relative paths
Parameters
- $view
- The path to the file, being '/' the 'views' directory
- $template
- The name of the template
Throws
Exception specifying the type of missing view.
|
public
string
|
#
get( string $view, array $_vars = array(), string $template = '' )
Renders a view and returns it
Renders a view and returns it
Parameters
- $view
- The path to the file, being '/' the 'views' directory
- $_vars
- The $vars to include in the view
- $template
- The template name
Returns
string The requested view
Throws
Exception specifying the type of missing view.
|
public
string
|
#
asset( string $path = '', boolean $return = FALSE )
Returns the web path for a given URL
Returns the web path for a given URL
Parameters
Returns
string $webPath
|
public
mixed
|
#
path( string $path = '', array $params = array(), boolean $return = FALSE )
Returns the web path for a given Route name
Returns the web path for a given Route name
Parameters
- $path
- The path identifier ('Home', 'Login', ...)
- $params
- The parameters of the URL (':id', ':name', ...)
- $return
- = FALSE. Whether to return or echo
Returns
mixed If $return = FALSE, the path. NULL otherwise
Throws
Exception If $path does not exist in the routing.ini
|
public
string
|
#
url( string $path, array $params = array() )
Alias for ::path with $return = TRUE. Use it for controllers
Alias for ::path with $return = TRUE. Use it for controllers
Parameters
- $path
- The path identifier ('Home', 'Login', ...)
- $params
- The parameters of the URL (':id', ':name', ...)
Returns
string The formatted URL
|
public
object
|
#
redirect( string $path = '' )
Performs a header redirection and a die();
Performs a header redirection and a die();
Parameters
Returns
object A JSON object with redirect instructions (if it's an ajax call) or a Location header.
|
public
Core\ParentController
|
#
add( string $varName, mixed $value )
Adds a var to the $this->show() renderer.
Adds a var to the $this->show() renderer.
Parameters
Returns
|
public
Core\ParentController
|
#
addJSVar( string $var, mixed $value, boolean $encoded = TRUE )
Adds a JS variable to the $this->show() renderer.
Adds a JS variable to the $this->show() renderer.
Parameters
Returns
|
public
Core\ParentController
|
#
addStyle( string $path, boolean|true $local = TRUE, boolean|true $minimize = TRUE )
Adds a script snippet to the $this->show() renderer.
Adds a script snippet to the $this->show() renderer.
Parameters
- $path
- The path to the asset (local or absolute)
- $local
- whether it's a relative (local) or absolute URL
- $minimize
- Use Minify library for the asset
Returns
|
public
Core\ParentController
|
#
addScript( string $path, boolean|true $local = TRUE, boolean|true $minimize = TRUE )
Adds a style snippet to the $this->show() renderer.
Adds a style snippet to the $this->show() renderer.
Parameters
- $path
- The path to the asset (local or absolute)
- $local
- whether it's a relative (local) or absolute URL
- $minimize
- Use Minify library for the asset
Returns
|
public
|
#
minimize( array $files, string $type = 'js' )
Adds a script with the minified URL of the $files
Adds a script with the minified URL of the $files
Parameters
- $files
- the files to add to the minified asset
- $type
- The type of minimized files
|
public
string
|
#
minimizeURL( array $files = [], string $type = 'js' )
Get the minified URL for the assets. This does NOT minimize files, just provide the minified url.
Get the minified URL for the assets. This does NOT minimize files, just provide the minified url.
Parameters
- $files
- The assets that you want to minify
- $type
- The type of minimized files
Returns
string
|
public
Core\ParentController
|
#
setTitle( string $title )
Sets a title for the website (different from the default one)
Sets a title for the website (different from the default one)
Parameters
Returns
|
public
Core\ParentController
|
#
setFavicon( string $favicon )
Sets a favicon for the website (different from the default one)
Sets a favicon for the website (different from the default one)
Parameters
- $favicon
- Route to the favicon asset
Returns
|
public
string
|
#
json( mixed $obj, integer $flags = 0 )
Returns $obj in a JSON format
Returns $obj in a JSON format
Parameters
- $obj
- $flags
- Flags to parse to json_encode
Returns
string JSON_encoded $obj
Usage
This function transforms a single-level array into a 2+ level array for the response
['success' => true, 'message' => 'Saved!', 'foo' => 'bar']
['message' => 'Saved!', 'foo' => 'bar']
Get transformed into
['success' => 1
'responseData' => [
'message' => 'Saved!',
'content' => ''
'foo' => 'bar'
]]
You are free to add as many variables as you like. They'll be added under 'responseData' key.
|
public
string
|
#
cache( string $path, array $vars = [] )
Gets the cache content for a given path
Gets the cache content for a given path
Parameters
- $path
- $vars
- Parameters to which render the file
Returns
string rendered file
Throws
Exception When the $path does not correspond (remember, there's a / -> _ conversion) to a chached file
|
public
|
#
compressWithMinify( )
Compresses $this->vars['script'] or $this->vars['style'] into a unique minified asset
Compresses $this->vars['script'] or $this->vars['style'] into a unique minified asset
|
Properties summary
protected
string
|
$path
The path where the framework is located: <framework_url>/<path>/app.php.
The path where the framework is located: <framework_url>/<path>/app.php.
|
|
protected
Core\Providers\Config
|
$config
The instance of the Config class.
The instance of the Config class.
|
|
protected
array
|
$vars
The required variables to show a view.
The required variables to show a view.
See
ParentController::show
|
|
protected
boolean
|
$ajax
If the request is an AJAX call. Set automatically by reading $_SERVER['HTTP_X_REQUESTED_WITH']
If the request is an AJAX call. Set automatically by reading $_SERVER['HTTP_X_REQUESTED_WITH']
|
|
protected
Core\ParentModel
|
$model
The instance of ParentModel.
The instance of ParentModel.
|
|
protected
string
|
$viewPath
Default path for files. For example, {view} = "home/index".
Default path for files. For example, {view} = "home/index".
|
|
protected
string
|
$templatePath
Default path for templates. For example, {template} = "default" or "email".
Default path for templates. For example, {template} = "default" or "email".
|
|
protected
Core\Hooks
|
$hooks
The instance of the Hooks class.
The instance of the Hooks class.
|
|