Frequently asked questions
From PRADO Wiki
Does PRADO have a database abstraction layer?
Complete DB support is provided starting from version v3.1, which includes DB abstraction layer and DB components and controls. You can, however, use one of the many existing PHP database abstraction libraries.
What is the difference between a Page and a Template?
Strictly speaking, these two are different concepts in PRADO and are inappropriate for comparison. Controls, i.e., components capable of presentation and user interaction, can have templates to help organize their presentation layout. A page is a special kind of control that may be requested directly by end-users, while other controls are managed by a page.
- must have templates (.page files)
- do not require page classes and default to TPage if none is specified
- allow page classes, but they must extend TPage
- TPage is a subclass of TTemplateControl
- must have control classes
- may have associated templates (.tpl files) if the control classes extends TTemplateControl
What is the difference between modules and services?
Briefly, when a request comes in, the request passes through a service (usually TPageService), which handles request fulfillment via mmodules (usually THttp* and TPage).
Modules implement the IModule interface. Modules are "behind the scenes" libraries for the application. Among other roles, modules provide the "model" component of the MVC pattern (if MVC is the design pattern in use).
Services implement the IService interface. Services are bridges between the application and the user. Whenever a user sends a request to the PRADO application, it first goes through a service. Most applications rely exclusively on TPageService and don't implement others.
How do I create links to other pages?
Because the URL scheme may change, developers should not use explicit links to other pages in a PRADO project. Developers should use the abstraction offered by constructUrl():
<a href="<%= $this->Service->constructUrl('Path.toPage') %>">LinkName</a>
If GET variables are involved:
<a href="<%= $this->Service->constructUrl('Path.toPage', GetVarsArray) %>">LinkName</a>
What is the difference between TPage->onInit() and TPage->onLoad()?
This is really a question of "What properties (including value) should controls have?" relative to a page's lifecycle. PRADO loads control properties in five stages, each overriding the last:
- Template data.
- Data set in onInit: This is where you should initialize components. Part of initialization is databinding. For example, on a page containing a listbox of countries, you would want fill it with countries at this stage. TListControl (and all its descendants TDropDownList, TCheckBoxList, etc), TDataGrid, TDataList, and TRepeater should be initialized here.
- ViewState data.
- POST data. If your controls haven't been initialized by this point, strange behavior may result.
- Data set in onLoad: If you want to override the POST values, you must do this here.
If no data affecting controls load in the ViewState and POST stages, onInit and onLoad are functionally equivalent.
What is the difference between Databind and Expression tags?
Expression tags run at the PreRender stage, which is before controls like TRepeater run.
Databind tags load their value at every databinding instance (e.g. each time TRepeater loads a data item). Indiscriminate use of Databind tags will work properly but potentially lower application performance.
How can I avoid hardcoding values like the site name?
This technique is used in the PradoBlog demo application.
- Create a separate configuration file, Name.xml:
<?xml version="1.0" encoding="utf-8"?> <parameters> <parameter id="ConfigKey" value="ConfigValue" /> </parameters>
- Link to the separate configuration file from application.xml under <application> <modules>: (Note the lack of the .xml extension.)
<module class="System.Util.TParameterModule" ParameterFile="Application.Path.toSettings.Name" />
- Use the configuration values
- ...in templates:
<%$ ConfigKey %>
- ...in classes:
- ...in templates:
How can I determine the currently signed-on user?
This will return an object implementing IUser:
How can I use PEAR libraries with PRADO?
PEAR libraries depend on having their root in the path, so if your PHP path does not include PEAR libaries, change it in php.ini or by amending the 'include_path' variable via ini_set().
However, this doesn't stop PRADO-style inclusion. Add the following to application.xml under <paths>:
<alias id="Pear" path="/path/to/pear" />
...and include PEAR libraries using Prado::using().
What do I need to do to deploy on a webfarm or cluster?
As in any web application, you need to make sure that sessions are not stored using PHP's default session storage. Use of a database or memcache or better is required.
In addition, PRADO creates validation and encryption keys randomly, and that information is stored on a per server basis. This means that you will get pagestate corruption errors (among others) when people switch across servers. To fix the issue, you can set your own keys via the application.xml file like this:
<module id="security" class="TSecurityManager" EncryptionKey="someKeyHere" ValidationKey="anotherKeyHere" />