User Guide & Reference Manual

Content Model

This model is the gateway to retrieving and searching all of the content published via the publish module. This includes content of content type created and managed at Publish > Content Types in the control panel.

Of course, you can also publish and manage existing content.

Initialization


$this->load->model('publish/content_model');
// methods now available at $this->content_model->x();

Method Reference

int new_content (int $type , int $user [, string $title = '' [, string $url_path = '' [, array $topics = array() [, array $privileges = array() [, string $publish_date = FALSE [, array $custom_fields = array()]]]]]])

Publish new content and get the returned $content_id. Technically, almost all the fields are optional. However, all standard content (i.e., with a Title and URL Path and potentially with topics, member group privileges, and a publish date) will use all of the function parameters.

The $custom_fields array is a simple key => value array likely generated automatically by the form builder library. However, if you are creating new content outside of the control panel, you can just as easily create this array yourself as long as each key is equal to the name of a custom field comprising the content type's fields.

void update_content (int $content_id [, string $title = '' [, string $url_path = '' [, array $topics = array() [, array $privileges = array() [, string $publish_date = FALSE [, array $custom_fields = array()]]]]]])

Update an existing piece of content.

boolean delete_content (int $content_id)

Delete an existing piece of content.

int add_hit (int $content_id)

Add a traffic hit to a piece of content.

int get_content_id (string $url_path)

Retrieve the content ID for a piece of content when given the URL path. This is used in the content controller.

int count_content ( [array $filters = array()])

Count all content items in the database matching the optional filters. These filters are identical to those of get_contents(). In fact, this method is a wrapper for that method, but uses a much more optimize method of obtaining a simple count number.

array get_content (int $content_id [, boolean $allow_future = FALSE])

Retrieve an array for a single piece of content from the database. By default, content with publish dates in the future will return FALSE.

array get_contents ( [array $filters = array() , boolean $counting = FALSE])

Retrieve one or more content items in an array as filtered with the optional filters.

Possible Filters:

You may also send any of your content types' custom fields as a filter, referencing the "system_name" of the custom field. For example, if

you have a field called "Program Type", you can send a filter called program_type. If your custom field conflicts

with another MySQL column name, you can send it using your content type's table as a prefix. For example: programs.program_type.

To pass the filter as a search parameter, wrap it in "%" (e.g., %test%).

Each piece of content has the following data: