bambinou
(Benoitrivaux)
1
Hello all,
I would like to know what does this $options = []; stands for please in the generated model from Gii. Why is it [] empty?
public function getUserLink()
{
$url = Url::to(['user/view', 'id'=>$this->UserId]);
$options = [];
return Html::a($this->getUserName(), $url, $options);
Thank you,
Ben
gugoan
(Gugoan)
2
bambinou
(Benoitrivaux)
3
Thank you so much Gustavo!
Ben
Stratigos
(Tmorningstar)
4
Also: http://php.net/manual/en/language.types.array.php (See the example referring to PHP 5.4)
I have worked in so many legacy PHP applications that I forget the "[]" shorthand all the time, and constantly type out "array()".
$options in every case that I’ve seen so far are HTML options. So in your case it would be <a></a> html options.
i.e.
<a class="someCssClass" rel="nofollow">
would be
['class'=>'someCssClass', 'rel'=>'nofollow']
here are the HTML Options list.
so
Html::a($this->getUserName(), $url, $options);
configured would be something like
Html::a($this->getUserName(), 'someurl.com', ['class'=>'someCssClass', 'id'=>'someID', 'rel'=>'nofollow']);
outputs a html "a" link
the above is the same as
<a href="someurl.com" class="test" id="someID" rel="nofollow">UserName</a>
in basic HTML
Also, whenever you see $clientOptions they are the plugins public configurable options.