Yii2 has several built-in helper classes to streamline common coding tasks, such as HTML, array, and JSON manipulation. These helper functions take the form of static classes (which means that they should be called statically rather than being instantiated) and live underneath the \yii\helpers
namespace. In this section, we'll go over several of the more common helpers.
Tip
Comprehensive documentation for all helpers Yii2 supports can be found on the Yii2 API documentation page underneath the helpers section at http://www.yiiframework.com/doc-2.0/.
The first helper commonly used in Yii2 is the URL helper. The URL helper helps us retrieve specific URLs, such as the base and home URL, and generate URL routes to specific paths. The URL helper lives under the yii\helpers\Url
namespace.
To retrieve the home URL of your application, use the home()
static method. Several different arguments can be passed to get different types of URLs:
$relativeHomeUrl = Url::home(); $absoluteHomeUrl...