For this discussion - lower case 'datasource' is different from 'Datasource', which is treated as a special type of Object in the Younicycle system. A Datasource is a datasource, with four additional (4) Php Actions (statements) which are automatically created and correctly pointed. These statements can also be edited to further manipulate the data.
An Object Datasource is used to exchange information between the tables, queries, or external XML-Resources, and visual components and data management. In general, all objects - Tables, Queries, Views - are datasources. If there is no need for additional data processing before output, it is preferable to directly use those objects in the GYRE editor. The specific object - Datasource - is useful when there is a need to analyze or process the data before output, or receive data from an external XML resource.
Below are two drawings reflecting the flow of data using Datasource.
To create a datasource, select Datasources from Y-Tree menu and then click on New Datasource or click the icon Datasource Builder from your internal Home page. When you create a datasource, you must specify its name, description (optional), pick a source from which the data will be selected and specify the limit on the number of records (default 0 - no limit), and a folder.
Creating a Datasource
A Table, or a Query, as well as an external XML-resource serve as data sources for a Datasource object. When sourcing data from tables or queries, one must also choose the name of the object from which the sample will be selected. If an external XML-resource is used as a source no additional selection steps are necessary.
After filling out all mandatory fields, click Create, creating a Datasource object.
When a Datasource is created, four additional Statements are also created - Select, Update, Insert, Delete. Each Statement is an Action type object (see (ref: 77)), allowing you to perform data manipulation of the Datasource.
The Statements are accessed through Edit properties/statements.
Editing a Select Statement
An example of a Select Statement for a table based datasource:
$records = $yc->getRecordsFromTable('products');
In this example, there is no additional data editing, only selection from a table. In this case, a Datasource object may be uneccessary as it is usually preferable to use tables directly. Datasource type objects are a little more resource-intensive and slower.
An example of Select Statement for a Datasource sampled from an external XML resource:
$result = array();
$xml_file = "http://weather.yahooapis.com/forecastrss?p=10002&u=F";
$xml = simplexml_load_file($xml_file);
foreach($xml->channel as $channel)
$row = array();
$row['Title']['value'] = (string)$channel->title;
$row['Weather']['value'] = (string)$channel->item->description;
$row['__id__']['value'] = 1;
$row['__author__']['value'] = 'weather.yahooapis.com';
$row['__date__']['value'] = date('Y-m-d H:i:s');
$result = $row;
The example above is a sample of weather data for the city of New York (10002) from Yahoo Weather. This would be a good use for a Datasource Object - as the Statement is required in order to pull only the desired data from a much larger set of data.
Attention! Fields "__id__", "__author__", "__date__" may be empty, but must be present in the result dataset. These fields are not displayed when viewing the datasource because they are systemic.
When done, the Datasource can be loaded to an Application, Template, Web Site Theme or Website Page via the GYRE in the Properties Palette.