datasource:DB

The datasource:DB is used when you need to make a SQL query and to quickly get all the information you'll need.

Reference

Go to Top
path data type req def uobj description
namestring
  
   The datasource name.
Has to be unique in the application.
sqlstring
  
   The SQL query to be executed by the datasource.
No ORDER BY nor LIMIT statements allowed.

Example:
  1. <datasource:DB name="my-ds">
  2. <sql><![CDATA[
  3.  
  4. SELECT * from pages
  5. WHERE pid=136
  6.  
  7. ]]></sql>
  8. </datasource:DB>
tablestring    Database table.

Example:
  1. <datasource:DB name="my-ds">
  2. <table>tt_news</table>
  3. </datasource:DB>
fieldsstring    List of fields to be queried.

Example:
  1. <datasource:DB name="my-ds">
  2. <fields>uid, title, short</fields>
  3. <table>tt_news</table>
  4. </datasource:DB>
whereswheres-section    Additional conditions to be added to the query.

Example:
  1. <datasource:DB name="my-ds">
  2. <fields>uid, title, short</fields>
  3. <table>tt_news</table>
  4. <wheres>
  5. <where>
  6. <term>pid</term>
  7. <comparison>=</comparison>
  8. <value>180</value>
  9. </where>
  10. </wheres>
  11. </datasource:DB>
enableFieldsstring    Adds enable fields to the sql query automatically (typically hidden=0 and deleted=0).

If string given, will be interpreted as the DB table on which to check for enableFields.
If true, the datasource will try to automatically determine the table name for enablefields.

If you have a SQL with more than one table, then you must set manually the enableFields, like this:
  1. $GLOBALS["TSFE"]->cObj->enableFields("fe_users")
beforeSqlFilterrunneable  
  
Allows to alter the raw data array that will be used to build the SQL parts, before building the whole query.
  • Input: the data array, containing filter-data and config,
  • Output: the altered data array.
beforeSqlExecrunneable  
  
Allows to alter the array that will be used to build the whole SQL query, before execution.
  • Input: the data array, containing sql parts, filter-data and config,
  • Output: the altered data array.
writableboolean false  Datasource can insert or update record in database.
The renderlet which use the datasource set a key.
Example
  1. <datasource:DB
  2. name="ds-test"
  3. writable="true"
  4. table="tx_ameostest"
  5. />
  6.  
  7. <renderlet:BOX name="bx-test">
  8. <datasource use="ds-test">
  9. <key>
  10. <userobj>
  11. <php><![CDATA[
  12. return (empty($this->oForm->_oParent->piVars['uid'])) ? 'new' : $this->oForm->_oParent->piVars['uid'];
  13. ]]></php>
  14. </userobj>
  15. </key>
  16. </datasource>
  17. <childs>
  18. <renderlet:TEXT name="title" />
  19. <renderlet:SUBMIT name="submit" />
  20. </childs>
  21. </renderlet:BOX>
beforeInsertionrunneable  
  
Alters the array of data, before insertion into the database.
  • Input: the data array,
  • Output: the altered data array.
afterInsertionrunneable  
  
Alters the array of data, after insertion into the database.
  • Input: the data array,
  • Output: the altered data array.
beforeEditionrunneable  
  
Alters the array of data, before insertion into the database, only if the record already exists in the database.
  • Input: the data array,
  • Output: the altered data array.
afterEditionrunneable  
  
Alters the array of data, after insertion into the database, only if the record already exists in the database.
  • Input: the data array,
  • Output: the altered data array.
beforeCreationrunneable  
  
Alters the array of data, before insertion into the database, only if the record don't exists in the database and is about to be created.
  • Input: the data array,
  • Output: the altered data array.
afterCreationrunneable  
  
Alters the array of data, after insertion into the database, only if the record has just been created.
  • Input: the data array,
  • Output: the altered data array.
link/ : Connects to an alternative DB if needed.
link/hoststring    Name or IP of the server hosting the alternative DB to connect to.
link/userstring    Alternative DB username.
link/passwordstring    Alternative DB password.
link/dbNamestring    Alternative DB name.

Examples

Go to Top

1). The following example presents how to create a datasource which is listing all the online users:

2). The bellow datasource will display all the countries which name is starting with the letter "A":