andriusk
(Andrius Kulbis)
December 5, 2013, 9:19am
1
Hello,
I want to create my own widgets.
Can the directory stucture be the same as Yii1, where I put my widget in components/ folder and views for the widget in componenets/views folder?
How should I call a widget in a view? The same as the bootstrap widgets are used? In view:
<?= MyWidgetClassName::widget(); ?>
?
Davey
(Davey975)
December 5, 2013, 9:23am
2
Yes, but you forgot the namespace i guess, for example:
<?php echo \frontend\widgets\RegisterForm::widget(); ?>
or
<?php
use frontend\widgets\RegisterForm;
echo RegisterForm::widget();
?>
andriusk
(Andrius Kulbis)
December 5, 2013, 9:46am
3
And what about rendering a view inside the widget:
<?php
namespace app\widgets;
use Yii;
use yii\base\Widget;
class BottomBar extends Widget
{
public function run()
{
return $this->render('bottomBar');
}
}
I put the bottomBar.php in widgets/views/. Now I use it in the view, generated by SiteController:
The view file does not exist: /home/user/public_html/views/site/bottomBar.php
Davey
(Davey975)
December 5, 2013, 10:21am
4
andriusk:
And what about rendering a view inside the widget:
<?php
namespace app\widgets;
use Yii;
use yii\base\Widget;
class BottomBar extends Widget
{
public function run()
{
return $this->render('bottomBar');
}
}
I put the bottomBar.php in widgets/views/. Now I use it in the view, generated by SiteController:
The view file does not exist: /home/user/public_html/views/site/bottomBar.php
Create a views directory inside your widgets directory. So it will be like widgets/views/bottomBar.php.