pclib  3.0.0
Lightweight PHP framework
Public Member Functions | Data Fields | Protected Attributes
Controller Class Reference

Base class for any application controller. More...

Inheritance diagram for Controller:
BaseObject

Public Member Functions

 init ()
 Called before every action. More...
 
 run ($action)
 Call action method of the controller, feeding it with required parameters. More...
 
 action ($rs)
 Call route $rs and return result of the controller's action. More...
 
 template ($path, $data=[])
 Create template $path, populated with $data. More...
 
 redirect ($route)
 Redirect to $route.
 
 model ($tableName, $id=null)
 Return model for table $tableName.
 
 selection ($from=null)
 Return orm\Selection class.
 
 authorize ($perm='')
 Check if user has permission $perm. More...
 
 outputJson (array $data, $code='')
 Output json data and exit. More...
 
- Public Member Functions inherited from BaseObject
 loadDefaults ($className=null)
 Load default parameters of class $className into object instance.
 
 setProperties (array $defaults)
 Set public properties of object from the array. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $name
 Name of the controller without postfix.
 
 $action
 Name of the called action without postfix.
 
 $authorizeRedirect = 'user/signin'
 authorize() fallback when user is not logged in.
 
 $allowDashInAction = true
 Convert url action some-thing into someThingAction() call.
 
- Data Fields inherited from BaseObject
 $serviceLocator
 var function() Return service object when requested with service().
 

Protected Attributes

 $app
 var App Link to application
 
 $ACTION_POSTFIX = 'Action'
 Each action method name must have following postfix. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 
- Protected Member Functions inherited from BaseObject
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Detailed Description

Base class for any application controller.

Define your controller, say 'products', in file controllers/ProductsController.php like class ProductsController extends Controller. Now you can define actions such as: function editAction() { ... return 'your html'; } It will be called on url '?r=products/edit'.

See also
App::run()

Member Function Documentation

◆ action()

action (   $rs)

Call route $rs and return result of the controller's action.

Parameters
string$rsRoute path i.e. 'comment/edit/id:1'
Returns
string $output

◆ authorize()

authorize (   $perm = '')

Check if user has permission $perm.

If not, redirect to sign-in or throw error. If $perm is empty, any logged user is allowed.

◆ init()

init ( )

Called before every action.

Override for controller's setup, testing access permissions, etc.

◆ outputJson()

outputJson ( array  $data,
  $code = '' 
)

Output json data and exit.

Use for actions called by ajax.

Parameters
array$data
string$codeHttp response code

◆ run()

run (   $action)

Call action method of the controller, feeding it with required parameters.

Parameters
Action$actioncalled action.

◆ template()

template (   $path,
  $data = [] 
)

Create template $path, populated with $data.

Parameters
string$pathPath to template
array$dataTemplate values
Returns
Tpl $template

Field Documentation

◆ $ACTION_POSTFIX

$ACTION_POSTFIX = 'Action'
protected

Each action method name must have following postfix.

Only action methods are callable by sending request from user browser.


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