Streams API Entries Driver
The entries driver is used to get entries from a stream. Entries are the rows in your stream.
You can call the entries driver like this:
$this->load->driver('Streams');
$this->streams->entries->function();
get_entries($params, $pagination_config = array())
The get_entries function allows you to pull entries from a streams table. This will run all of the entries through the various formatting and filtering that each field type has.
$params
The params array contains all of the data to affect what data you get back from the get_entries function. The only two parameters that are required are stream and namespace.
$params = array(
'stream' => 'faqs',
'namespace' => 'faq'
);
$entries = $this->streams->entries->get_entries($params);
Here is a full list of parameters and what they do:
Parameter | Type | Default | |
---|---|---|---|
stream | string | Slug of the stream you want to get entries from. | |
namespace | string | Namespace of the stream you want to get entries from. | |
limit | int | Number of entries to limit the results to. | |
offset | int | Number to offset the results by. | |
order_by | string | created | Specify a field to order by. |
sort | string | desc | The sort order. Ascending (asc), descending (desc), or random. |
date_by | string | created | The field to run date parameters through. This is the field that is used when using other time-based result restrictions such as show_upcoming. |
year | int | Restrict results to a year (uses the date_by field). | |
month | int | Restrict results to a month (uses date_by field). Takes the numerical month value. | |
day | int | Restrict results to a day (uses the date_by field). Takes a numerical day value. | |
show_upcoming | 'yes' or 'no' | yes | Choose yes or no to show entries dated in the future (uses the date_by field). |
show_past | 'yes' or 'no' | yes | Choose yes or no to show entries dated in the past (uses the date_by field). |
where | string | Allows you to specify a where parameter using the following structure: field_slug = 'value'. | |
exclude | string | IDs of entries to exclude separated by a pipe character (|). Ex: 1|4|7 | |
exclude_called | 'yes' or 'no' | no | Set to 'yes' to exclude entries that have already been called in the same page load. |
disable | string | Allows you to disable fields and their formatting. You can specify multiple fields by separating them with a pipe character (|). This is a useful if you want to bypass the extra work that streams does to format fields that you aren't using. | |
paginate | string | 'yes' or 'no' (default is 'no') | Allows you to enable pagination (generate a string with page navigation links). Pagination feature is tied to the pag_segment option below |
pag_segment | int | 2 | Indicate which uri segment the CI pagination helper have to look into, to get the target page index. For instance, in the "http://my.app.com/controller/method/page_index", the pag_segment should be 3 ( 1 refers to 'controller', and 2 refers to 'method' |
$pagination_config
Streams uses identical pagination config to the CodeIgniter pagination parameters. You usually won't need to touch these if you are displaying your pagination in the control panel.
Return Format
The get_entries()
function will return an array with several values:
Key | Format | |
---|---|---|
entries | array | An array of the entries you wanted to return. |
pagination | string | The pagination code if you are using pagination (need to set paginate and pag_segment options) |
total | int | Total results (total, not just based on current page) |
get_entry($entry_id, $stream_slug, $namespace_slug, $format = true)
The get_entry()
function allows you to get a single entry. If you'd like to bypass the streams formatting, you can set the fourth parameter to false
.
delete_entry($entry_id, $stream_slug, $namespace_slug)
Allows you to delete an entry.
insert_entry($entry_data, $stream_slug, $namespace_slug, $skips = array(), $extra = array())
Allows you to add an entry in a stream.
$entry_data
The $entry_data parameter is an array of values for each field. This data is not run through any field validation (for required, unique, etc). Keep in mind that many field types have a pre_save function that formats data before it gets to the database columns.
$skips
The $skips parameter is an array of field slugs that you would like streams to ignore. These fields will not be processed to included in the entry.
$extra
The $extra parameter is an associative array of data to be added to the database by bypassing any field formatting. For instance, if you have a field that you added to your streams table without using a field and field type, you could include that data there, and the insert_entry
function would simply add it to the data to be inserted.
Example
$entry_data = array(
'question' => 'Why is the sky blue?',
'answer' => 'Because of science.'
);
$this->streams->entries->insert_entry($entry_data, 'faqs', 'faq');
In this example, we have extra data.
$entry_data = array(
'question' => 'Why is the sky blue?',
'answer' => 'Because of science.'
);
$this->streams->entries->insert_entry($entry_data, 'faqs', 'faq', array(), array('not_added_by_streams' => 'extra value'));
update_entry($entry_id, $entry_data, $stream, $namespace, $skips=array(), $extra = array(), $include_only_passed = true)
Allows you to update an entry in the stream. Identical to insert_stream
, except the first parameter is the id of the entry you want to update.
$entry_data = array(
'answer' => 'Because of magic.'
);
$this->streams->entries->update_entry(2, $entry_data, 'faqs', 'faq');
$include_only_passed
The $include_only_passed parameter is a boolean indicating whether or not fields should be modified if they are not present in the $entry_data
array. It defaults to true
, so only the included fields are modified. If set to false
, any fields not in the $entry_data
array will be updated to NULL in the database.