pclib
3.0.0
Lightweight PHP framework
|
Gives global access to web application. More...
Public Member Functions | |
__construct ($name) | |
Load config and sessions, read route. More... | |
setContent ($content) | |
Set content of the webpage to be displayed. More... | |
setLayout ($path) | |
Set layout template of the application. More... | |
log ($category, $message_id, $message=null, $item_id=null) | |
Store message to log, using application Logger. More... | |
setService ($name, IService $service) | |
Register application service such as Db or Logger. More... | |
addConfig ($source) | |
Load application configuration. More... | |
environmentIp (array $env) | |
Set $app->environment variable by server ip-address. More... | |
redirect ($route, $code=null) | |
Perform redirect to $route. More... | |
setLanguage ($language) | |
Initialize application Translator and enable translation to the $language. More... | |
path ($path) | |
Replace path variables e.g. More... | |
text ($s) | |
Translate string $s. More... | |
message ($message, $cssClass=null) | |
Display flash message. More... | |
error ($message, $cssClass=null) | |
Display error message and exit application. More... | |
httpError ($code, $message, $cssClass=null) | |
Display error message with http response code header and exit application. More... | |
getSession ($name, $ns=null) | |
Get application session variable. More... | |
setSession ($name, $value, $ns=null) | |
Set application session variable. More... | |
deleteSession ($name=null, $ns=null) | |
Delete application session variable. More... | |
run ($rs=null) | |
Execute method of the controller. More... | |
out () | |
Display webpage. 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 aplication. | |
$config = array() | |
Application configuration. | |
$paths | |
application base paths (webroot, basedir, baseurl and pclib) | |
$layout | |
Master template of the website. More... | |
$services = array() | |
Storage of the global services - Db, Auth, Logger etc. | |
$environment = '' | |
Current environment (such as 'develop','test','production'). | |
$debugMode = false | |
Enabling debugMode will display debug-toolbar. | |
$errorHandler | |
var ErrorHandler | |
Data Fields inherited from BaseObject | |
$serviceLocator | |
var function() Return service object when requested with service(). | |
Protected Member Functions | |
createDefaultService ($serviceName) | |
Return default service object or null, if service must be created by user. More... | |
Protected Member Functions inherited from BaseObject | |
service ($service, $default=null) | |
Try acquire $service and load it into property $this->$service. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from BaseObject | |
static | defaults () |
Set or retireve default parameters of the object. More... | |
Gives global access to web application.
It is facade for application services and general datastructures. Features:
__construct | ( | $name | ) |
Load config and sessions, read route.
string | $name | Unique name of the application. |
addConfig | ( | $source | ) |
Load application configuration.
$source must be valid php-file which containing array $config or $config array itself. Can be called more than once - configurations will be merged. Set $config variable.
string | array | $source | Path to configuration file or array of config-parameters. |
|
protected |
Return default service object or null, if service must be created by user.
string | $serviceName |
deleteSession | ( | $name = null , |
|
$ns = null |
|||
) |
Delete application session variable.
Without parameters, it will delete whole application session.
string | $name | name of variable |
string | $ns | (optional) Namespace |
environmentIp | ( | array | $env | ) |
Set $app->environment variable by server ip-address.
array | $env | Array of ipAddress:environmentName pairs. |
error | ( | $message, | |
$cssClass = null |
|||
) |
Display error message and exit application.
getSession | ( | $name, | |
$ns = null |
|||
) |
Get application session variable.
Session variables are stored in their own namespace $ns. By default it is application name, so sessions for different applications does not collide. Variable name can be plain: 'user' or with group: 'pclib.user'. All system variables uses group 'pclib'.
string | $name | Variable name. |
string | $ns | (optional) Namespace. |
httpError | ( | $code, | |
$message, | |||
$cssClass = null |
|||
) |
Display error message with http response code header and exit application.
log | ( | $category, | |
$message_id, | |||
$message = null , |
|||
$item_id = null |
|||
) |
Store message to log, using application Logger.
If application has no Logger service, this method does nothing. For the parameters see Logger::log()
message | ( | $message, | |
$cssClass = null |
|||
) |
Display flash message.
Layout template must contains messages tag. In message %s arguments can be used. Messages are also translated with Translator. You can call message() even before redirect. Example: $app->message('File %s not found', $fileName);
string | $message | |
string | $cssClass | Css-class of the message div |
mixed | $args | Variable number of message arguments |
out | ( | ) |
Display webpage.
Get $layout template populated with content and display it. You must setup layout and content first.
path | ( | $path | ) |
Replace path variables e.g.
{basedir}
redirect | ( | $route, | |
$code = null |
|||
) |
Perform redirect to $route.
Example: $app->redirect("products/edit/id:$id");
string | array | $route | |
http | code (e.g. 301 Moved Permanently) See also PClib route |
run | ( | $rs = null | ) |
Execute method of the controller.
Without parameters, route is read from current url. Route 'products/add' means: call method ProductsController->addAction();
string | $rs | Route string. See PClib route |
setContent | ( | $content | ) |
Set content of the webpage to be displayed.
It replaces {CONTENT} placeholder in layout. Call out() for displaying website with content.
string | $content | Content placed into layout. |
setLanguage | ( | $language | ) |
Initialize application Translator and enable translation to the $language.
You can access current language as $app->language.
string | $language | Language code such as 'en' or 'source'. |
setLayout | ( | $path | ) |
Set layout template of the application.
Any page added with function setContent() will be put inside layout template. Example: $app->setLayout('tpl/website.tpl');
string | $path | Path to website template. |
setService | ( | $name, | |
IService | $service | ||
) |
setSession | ( | $name, | |
$value, | |||
$ns = null |
|||
) |
Set application session variable.
string | $name | name of session variable |
mixed | $value | value of variable |
string | $ns | (optional) Namespace |
text | ( | $s | ) |
Translate string $s.
Uses Translator service if present, otherwise return unmodified $s. Example: $app->text('File %s not found.', $fileName);
string | $s | String to be translated. |
mixed | $args | Variable number of arguments. |
$layout |
Master template of the website.