pclib
3.0.0
Lightweight PHP framework
|
Base class for any application controller. More...
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... | |
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'.
action | ( | $rs | ) |
Call route $rs and return result of the controller's action.
string | $rs | Route path i.e. 'comment/edit/id:1' |
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 | ( | ) |
Called before every action.
Override for controller's setup, testing access permissions, etc.
outputJson | ( | array | $data, |
$code = '' |
|||
) |
Output json data and exit.
Use for actions called by ajax.
array | $data | |
string | $code | Http response code |
run | ( | $action | ) |
Call action method of the controller, feeding it with required parameters.
Action | $action | called action. |
template | ( | $path, | |
$data = [] |
|||
) |
Create template $path, populated with $data.
string | $path | Path to template |
array | $data | Template values |
|
protected |
Each action method name must have following postfix.
Only action methods are callable by sending request from user browser.