Closed blonder413 closed 9 years ago
strange, can't reproduce it but please try this one
"require": {
...
"ijackua/yii2-sharelinks-widget": "1.0.*",
....
that line is created when I use composer require and it works, but I don't know how use the widget, I try with the example code but nothing.
ok, I see
it looks like you are not using echo
before the widget, I have update doc a little
try the simplest one include way (with explicit echo
)
<?php echo \ijackua\sharelinks\ShareLinks::widget(); ?>
if it works, then see the README on how to modify buttons appearance with custom view
When I try to put the code say this:
Unknown Method – yii\base\UnknownMethodException Calling unknown method: app\controllers\SiteController::shareUrl()
this is my view
<?php
use ijackua\sharelinks\ShareLinks;
use yii\helpers\Html;
?>
....
<div class="socialShareBlock">
<?= Html::a('<i class="icon-facebook-squared"></i>', $this->context->shareUrl(ShareLinks::SOCIAL_FACEBOOK),
['title' => 'Share to Facebook']) ?>
<?= Html::a('<i class="icon-twitter-squared"></i>', $this->context->shareUrl(ShareLinks::SOCIAL_TWITTER),
['title' => 'Share to Twitter']) ?>
<?= Html::a('<i class="icon-linkedin-squared"></i>', $this->context->shareUrl(ShareLinks::SOCIAL_LINKEDIN),
['title' => 'Share to LinkedIn']) ?>
<?= Html::a('<i class="icon-gplus-squared"></i>', $this->context->shareUrl(ShareLinks::SOCIAL_GPLUS),
['title' => 'Share to Google Plus']) ?>
<?= Html::a('<i class="icon-vkontakte"></i>', $this->context->shareUrl(ShareLinks::SOCIAL_VKONTAKTE),
['title' => 'Share to Vkontakte']) ?>
<?= Html::a('<i class="icon-tablet"></i>', $this->context->shareUrl(ShareLinks::SOCIAL_KINDLE),
['title' => 'Send to Kindle']) ?>
</div>
Ah... you can't simply use $this->context->shareUrl
calls in your action views.
Calling unknown method: app\controllers\SiteController::shareUrl()
means that $this->context
is a Controller and view render called from a controller.
You must render $this->context->shareUrl
calls in a context of Widget.
Look at example one more time
<?php echo \ijackua\sharelinks\ShareLinks::widget(
[
'viewName' => '@app/views/mypath/shareLinks.php'
]
); ?>
$this->context->shareUrl
call will work ONLY inside @app/views/mypath/shareLinks.php
view file - as shareUrl
is a ShareLinks widget's function, and view render should be called from Widget.
It is how Widgets works in Yii2.
thank you for your support, now I understand. I thought I should use one of the two, not both (view and widget). It's working now. Only one more thing, please, how can I add fontello icon to my project?
Great.
how can I add fontello icon to my project?
Generate custom font on http://fontello.com/ and add it to html according to instruction
But maybe Font-Awesome would be easier to use for you, instruction , but don't forget to change html for icons <i class="icon-facebook-squared"></i>
on those that is provided by Font-Awesome
when I add "ijackua/yii2-sharelinks-widget": "dev-master" to composer.json and execute composer update an error occurs, but when I use "composer require ijackua/yii2-sharelinks-widget" the problem is that widget doesn't work. Can you be more specific in the example, please?