SproutCMS

This is the code documentation for the SproutCMS project

function tryUrl()

Attempts to convert a link specification into a URL

This differs in behaviour to `Lnk::url` as it will return null if the spec is
empty, but *not* malformed; it still throws an InvalidArgumentException in that case.
It will also return null if a RowMissingException is thrown by the link spec instance
during processing.

Helpful when you wish to avoid breaking pages when someone deletes the linked record, e.g. a blog post,
without updating the corresponding link(s).

Usage

string|null Lnk::tryUrl ( string $spec );

Arguments

  1. string $spec
    A JSON link specification

Exceptions thrown

  • InvalidArgumentException
    If the link specification is malformed

Return value

  • string
    The target URL or null if the spec is empty or if a RowMissingException
                        is thrown during processing.
  • null
    The target URL or null if the spec is empty or if a RowMissingException
                        is thrown during processing.