Feeds

Type
Class
Namespace
craft\feeds
Inherits
craft\feeds\Feeds » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
3.0.0
Deprecated in
in 3.4.24

The Feeds service provides APIs for fetching remote RSS and Atom feeds.

An instance of the Feeds service is globally accessible in Craft via Craft::$app->feeds.

View source (opens new window)

# Public Properties

Property Description
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component.

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns the value of a component property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getFeed() Fetches and parses an RSS or Atom feed, and returns info about the feed and its items.
getFeedItems() Fetches and parses an RSS or Atom feed, and returns its items.
hasEventHandlers() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() (opens new window) Initializes the object.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
trigger() (opens new window) Triggers an event.

# getFeed()

Since
3.0.37

Fetches and parses an RSS or Atom feed, and returns info about the feed and its items.

The returned array will have the following keys:

  • authors – An array of the feed’s authors, where each sub-element has the following keys:
    • name – The author’s name
    • url – The author’s URL
    • email – The author’s email
  • categories – An array of the feed’s categories, where each sub-element has the following keys:
    • term – The category’s term
    • scheme – The category’s scheme
    • label – The category’s label
  • copyright – The copyright info for the feed, or null uf not known.
  • dateCreated – The feed’s creation date, or null if not known.
  • dateUpdated – The feed’s last modification date, or null if not known.
  • description – The feed’s description, or null if not known.
  • generator – The feed’s generator, or null if not known.
  • id – The feed’s ID, or null if not known.
  • items – An array of the feed’s items. See getFeedItems() for a list of keys each element in this array will contain.
  • language – The feed’s language, or null if not known.
  • link – The link to the feed’s HTML source, or null if not known.
  • title – The feed’s title, or null if not known.

View source (opens new window)

Arguments

Returns

array (opens new window) – The feed info

Throws

Example

$feedUrl = 'https://craftcms.com/news.rss';
$feed = Craft::$app->feeds->getFeed($feedUrl, 10);

# getFeedItems()

Fetches and parses an RSS or Atom feed, and returns its items.

Each element in the returned array will have the following keys:

  • authors – An array of the item’s authors, where each sub-element has the following keys:
    • name – The author’s name
    • url – The author’s URL
    • email – The author’s email
  • categories – An array of the item’s categories, where each sub-element has the following keys:
    • term – The category’s term
    • scheme – The category’s scheme
    • label – The category’s label
  • content – The item’s main content.
  • contributors – An array of the item’s contributors, where each sub-element has the following keys:
    • name – The contributor’s name
    • url – The contributor’s URL
    • email – The contributor’s email
  • date – A \craft\feeds\DateTime object representing the item’s date.
  • dateUpdated – A \craft\feeds\DateTime object representing the item’s last updated date.
  • permalink – The item’s URL.
  • summary – The item’s summary content.
  • title – The item’s title.

View source (opens new window)

Arguments

Returns

array (opens new window) – The list of feed items.

Throws

Example

$feedUrl = 'https://craftcms.com/news.rss';
$items = Craft::$app->feeds->getFeedItems($feedUrl, 10);