Skip to content

Commit

Permalink
add View::createAbsoluteUrl() method as a shortcut to `CApplication…
Browse files Browse the repository at this point in the history
…::createAbsoluteUrl()`
  • Loading branch information
klimov-paul committed May 20, 2024
1 parent ef2ae82 commit df37f78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Yii1 Symfony Mailer extension

- Enh: Added passing email message instance via `$_message` context variable to the template (klimov-paul)
- Enh: Added passing template context variables to the layout template (klimov-paul)
- Enh: Added `View::createAbsoluteUrl()` method as a shortcut to `CApplication::createAbsoluteUrl()` (klimov-paul)


1.0.0, May 10, 2024
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ $this->layout = 'particular-layout';
?>
<h1>Greetings</h1>
<p>Context var "name" = <?php echo CHtml::encode($name) ?></p>

<a href="<?php $this->createAbsoluteUrl('mail/unsubscribe', ['email' => $_message->getTo()[0]->getAddress()]) ?>">Unsubscribe</a>
```


Expand Down
16 changes: 16 additions & 0 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,20 @@ public function endClip(): void
{
$this->endWidget(ClipWidget::class);
}

/**
* Creates an absolute URL based on the given controller and action information.
*
* @since 1.0.1
*
* @param string $route the URL route. This should be in the format of 'ControllerID/ActionID'.
* @param array $params additional GET parameters (name=>value). Both the name and value will be URL-encoded.
* @param string $schema schema to use (e.g. http, https). If empty, the schema used for the current request will be used.
* @param string $ampersand the token separating name-value pairs in the URL.
* @return string the constructed URL
*/
public function createAbsoluteUrl(string $route, array $params = [], string $schema = '', string $ampersand = '&'): string
{
return Yii::app()->createAbsoluteUrl($route, $params, $schema, $ampersand);
}
}

0 comments on commit df37f78

Please sign in to comment.