-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document lt_setvar, lt_getvar and lt_isvar
- Loading branch information
Showing
2 changed files
with
128 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
# Libtables concepts | ||
|
||
## Minimize boilerplate PHP/HTML code | ||
|
||
Libtables was initially created to avoid the repetitiveness of formatting tabular data with | ||
HTML table elements by hand. Further on, other functionality such as edit-in-place and | ||
insert mechanics were added. Libtables allows you to describe the elements and functionality | ||
the tables need to have, rather than spell them out for each item individually. In other words, | ||
Libtables is more of a declarative way to create web-tables than an imperative way. | ||
|
||
## Harness the strengths of SQL | ||
|
||
Where possible, Libtables allows you to use the strengths of SQL, as opposed to many | ||
ORMs which completely abstract the SQL away. In most Libtables functions you can use | ||
the full power of the SQL language. As such it is expected that you do type-conversions | ||
and string concatenations in the SQL queries, rather than afterwards using PHP. | ||
|
||
The drawback of this approach is that switching a Libtables application from one database | ||
type to another may take more time to deal with differences in SQL dialects. | ||
|
||
## Primary keys | ||
|
||
Libtables requires the first column of every query to contain a numeric primary key larger | ||
than zero. Furthermore the 'edit' functionality assumes this column to be named 'id'. It's | ||
possible to use a different column name for a specific table by defining them in the | ||
'id_columns' item of the $lt_settings array in config.php. | ||
|
||
## Hashtags and column numbers | ||
|
||
Each query to populate a Libtables table needs to start with the unique "id" column for | ||
that table. This column is not shown to the user but is used internally all the time. We | ||
count columns starting from zero, so column 0 is the id number and column 1 is the first | ||
column visible to the user. | ||
|
||
Most Libtables function parameters that allow text inputs will interpret hashtags inside | ||
these strings. The basic hashtags are column numbers such as "#0", "#1", "#2" etc to use | ||
the values of each row in texts that relate to that row. For instance the 'appendcell' | ||
option commonly uses #0 to construct a URL with an id number inside it. | ||
|
||
## Blocks | ||
|
||
The main organizing unit in Libtables is the block. A block can contain any HTML | ||
and/or PHP, but generally it will contain one or more lt_* functions. Blocks need | ||
to be separate files because they have to be loaded both from regular pageviews | ||
as well as AJAX-calls to Libtables' data.php. The latter is done so that the server | ||
can verify whether certain operations are allowed. | ||
|
||
Blocks are included in the main flow of your website by calling lt_print_block(). | ||
This function can be used recursively, so a block can include another block. Some | ||
libtables workflows operate by replacing the content of the current block with that | ||
of another block. | ||
|
||
## Variables | ||
|
||
You should not use global PHP variables like $_SESSION or $_GET in blocks, because | ||
Libtables calls blocks on AJAX context where they may not be available. To store state | ||
between blocks, such as 'the logged in user' or 'the currently selected product', you | ||
should use the lt_setvar(), lt_getvar() and lt_isvar() functions instead. | ||
|
||
These variables can be used in all SQL queries issued from within libtables by using | ||
named parameter syntax (eg. "SELECT * FROM product WHERE id = :product"). | ||
|
||
PHP and Libtables variable names starting with 'lt_' are reserved for use by Libtables | ||
and should not be defined within your application. | ||
# Libtables concepts | ||
|
||
## Minimize boilerplate PHP/HTML code | ||
|
||
Libtables was initially created to avoid the repetitiveness of formatting tabular data with | ||
HTML table elements by hand. Further on, other functionality such as edit-in-place and | ||
insert mechanics were added. Libtables allows you to describe the elements and functionality | ||
the tables need to have, rather than spell them out for each item individually. In other words, | ||
Libtables is more of a declarative way to create web-tables than an imperative way. | ||
|
||
## Harness the strengths of SQL | ||
|
||
Where possible, Libtables allows you to use the strengths of SQL, as opposed to many | ||
ORMs which completely abstract the SQL away. In most Libtables functions you can use | ||
the full power of the SQL language. As such it is expected that you do type-conversions | ||
and string concatenations in the SQL queries, rather than afterwards using PHP. | ||
|
||
The drawback of this approach is that switching a Libtables application from one database | ||
type to another may take more time to deal with differences in SQL dialects. | ||
|
||
## Primary keys | ||
|
||
Libtables requires the first column of every query to contain a numeric primary key larger | ||
than zero. Furthermore the 'edit' functionality assumes this column to be named 'id'. It's | ||
possible to use a different column name for a specific table by defining them in the | ||
'id_columns' item of the $lt_settings array in config.php. | ||
|
||
## Hashtags and column numbers | ||
|
||
Each query to populate a Libtables table needs to start with the unique "id" column for | ||
that table. This column is not shown to the user but is used internally all the time. We | ||
count columns starting from zero, so column 0 is the id number and column 1 is the first | ||
column visible to the user. | ||
|
||
Most Libtables function parameters that allow text inputs will interpret hashtags inside | ||
these strings. The basic hashtags are column numbers such as "#0", "#1", "#2" etc to use | ||
the values of each row in texts that relate to that row. For instance the 'appendcell' | ||
option commonly uses #0 to construct a URL with an id number inside it. | ||
|
||
## Blocks | ||
|
||
The main organizing unit in Libtables is the block. A block can contain any HTML | ||
and/or PHP, but generally it will contain one or more lt_* functions. Blocks need | ||
to be separate files because they have to be loaded both from regular pageviews | ||
as well as AJAX-calls to Libtables' data.php. The latter is done so that the server | ||
can verify whether certain operations are allowed. | ||
|
||
Blocks are included in the main flow of your website by calling lt_print_block(). | ||
This function can be used recursively, so a block can include another block. Some | ||
libtables workflows operate by replacing the content of the current block with that | ||
of another block. | ||
|
||
## Variables | ||
|
||
You should not use global PHP variables like $\_SESSION or $\_GET in blocks, because | ||
Libtables calls blocks on AJAX context where they may not be available. To store state | ||
between blocks, such as 'the logged in user' or 'the currently selected product', you | ||
should use the lt_setvar(), lt_getvar() and lt_isvar() functions instead. | ||
|
||
These variables can be used in all SQL queries issued from within libtables by using | ||
named parameter syntax (eg. "SELECT * FROM product WHERE id = :product"). | ||
|
||
PHP and Libtables variable names starting with 'lt_' are reserved for use by Libtables | ||
and should not be defined within your application. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters