I am in the process of learning Yii2 more in depth, so I was wondering if it is possible for a widget to have something similar to actions in a controller?
In example:
class WTest extends Widget {
public ...;
public function init() {
...
}
public function run() {
Pjax::begin();
echo "<a href='".Yii::$app->urlManager->createAbsoluteUrl("test/add")."'>Add test</a>";
Pjax::end();
}
public function addThing() {
echo "hola"
}
}
Then in a controller do:
class TestController extends Controller
{
public function actionAdd() {
$wObj = new WTest;
return $wObj->addThing();
}
}
The issues with this way is that I loose all the parameters set when calling the widget in the form, since I am calling "new WTest", it is a new instance. I have tried using a static method too, but similar issue, any ideas?
UPDATE In the view, I am calling the widget like this:
WTest::widget([
'test' => 'hi'
]);
singletonpattern for it. - ThanhPV