Yii2 — How to bring the module in View of the main page?

Read the official Doc for Yii2 as for the Modules: https://www.yiiframework.com/doc/guide/2.0/ru/stru... In principle, everything is clear and logical, but given previous experience with CMS-kami immediately there was a burning desire to sculpt the test module and display it for example in seitbai the main page:

5de422a86e561010871003.jpeg

And here came the plugging, as shown in "strange" action of another controller, if the module is "finished software components, consisting of models, views, controllers and other auxiliary components."?

The link type www.site.ru/samplemodule the module is open, everything is OK, what are the ways to integrate it say www.site.ru/index? if the module has its own view, controller and even the model. Or have all such things to do with widgets?

Now the idea is this - in a method of the controller for the Main page to call the object Module, to carry out all stages of its methods until render() but in the end, to pack all into a variable $module and send it into the view the Main page with other data.

If the rough:

namespace app\controllers;
use app\modules\banner\Banner;

class SiteController extends Controller
{

 public function actionIndex(){

 $banner = new Banner();
 $data = 'Lorem ipsum...';

 return $this->render('index', [
 'banner' => $banner,
 'data' => $data,
])
}

}


namespace app\modules\banner;

class Banner extends \yii\base\Module
{

 public $controllerNamespace = 'app\modules\banner\controllers';
 public function init()
{
parent::init();
}
}



namespace app\modules\banner\controllers;
use yii\web\Controller;

class DefaultController extends Controller
{
 public function actionIndex()
{
 return $this->render('index');
}
}
April 2nd 20 at 17:11
2 answers
April 2nd 20 at 17:13
Yes well, nonsense. modules for this.
have all these things to do with widgets
That's what I think. Too complex structure and the working principle for a simple "cubes" type of weather forecast or currency exchange rates. - trace_Kuh commented on April 2nd 20 at 17:16
The only thing that is good - the module has its own render() method and your design to do. - trace_Kuh commented on April 2nd 20 at 17:19
@trace_Kuh, the widget is not present?) - kiel.Lind commented on April 2nd 20 at 17:22
@trace_Kuh, just make a widget - Willa_Orn commented on April 2nd 20 at 17:25
@kiel.Lind, the word "widget" for some reason I remember this cartoon from my childhood )
Widgetlogo.jpg - trace_Kuh commented on April 2nd 20 at 17:28
@Willa_Orn, Yes, the campaign will have to do so. - trace_Kuh commented on April 2nd 20 at 17:31
@trace_Kuhmodule Yes, complete application.
For example, the module news, comments, subscriptions, likes, and other garbage. This module may be a widget with "popular", "hot", "most discussed" and the like. And it can be used on the main page or any other page. - rodrigo_Stok commented on April 2nd 20 at 17:34
@rodrigo_Stok, of course. Just the terminology is different everywhere, in WordPress - plugins in the Joomla - modules in yii - widgets. - trace_Kuh commented on April 2nd 20 at 17:37
@trace_Kuh, well, himself yii cms is irrelevant))) - rodrigo_Stok commented on April 2nd 20 at 17:40
April 2nd 20 at 17:15
the module is "finished software components, consisting of models, views, controllers and other auxiliary components."

You could think of. Only, let's say you have in the app, and maybe even not in one but in at least two (site and admin) is the model in the /common/models and it should be used in a certain module of the same application, you could be her clone in the module, or did you use the one in /common/models?
For cleanliness you can, of course, in the module to make the heir to the model. But what about, for example, with helpers. I somehow think that every developer has at least inherited Html, ArrayHelper, StringHelper, etc. Their Doge in modules for completeness to produce?

Find more questions by tags Yii