{"id":282708,"date":"2016-12-19T16:05:03","date_gmt":"2016-12-19T13:05:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=282708"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=282708","title":{"rendered":"Yii2: \u0414\u0435\u043b\u0430\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438"},"content":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0441\u0435\u0445! \u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Yii2 \u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u043a\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0434\u0443\u043b\u044c. <\/p>\n<p>  \u0412 Yii2 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0438\u043d\u0443\u0441 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u0442.\u043a. \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0430 \u0438 \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 POST-\u0437\u0430\u043f\u0440\u043e\u0441 (\u0445\u043e\u0442\u044f \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u0438\u0434\u0436\u0435\u0442\u044b \u0442\u0430\u043a \u0441 \u043d\u0435\u043a\u0438\u043c\u0438 \u043a\u043e\u0441\u0442\u044b\u043b\u044f\u043c\u0438).<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435.<\/p>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<ul>\n<li>\u041c\u043e\u0434\u0443\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435<\/li>\n<li>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 \u0411\u0414 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044f (\u0432\u043a\u043b\u044e\u0447\u0435\u043d\/\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d) \u0438 \u0435\u0433\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439<\/li>\n<li>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/li>\n<li>\u0412\u044b\u0432\u043e\u0434 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u0445 \u043d\u0443\u0436\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/li>\n<\/ul>\n<p>  \u0417\u0430 \u0438\u0434\u0435\u044e \u0432\u0437\u044f\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432 CMS OpenCart.<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f <b>dispatcher<\/b> \u0447\u0435\u0440\u0435\u0437 <b>gii<\/b> \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 <b>web.php<\/b><\/p>\n<pre><code class=\"php\">'dispatcher' =&gt; [      'class' =&gt; 'app\\modules\\dispatcher\\Module', ], <\/code><\/pre>\n<p>  \u0412 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f <b>app\\modules\\dispatcher<\/b> \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <b>BasicModule<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 <b>\\yii\\base\\Module<\/b>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">BasicModule.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  namespace app\\modules\\dispatcher;  use app\\modules\\dispatcher\\components\\Controller; use app\\modules\\dispatcher\\models\\LayoutModule;  \/**  *  * Class Module  * @package app\\modules\\dispatcher\\components  *  *\/ class BasicModule extends \\yii\\base\\Module {     const POSITION_HEADER = 'header';     const POSITION_FOOTER = 'footer';     const POSITION_LEFT = 'left';     const POSITION_RIGHT = 'right';      \/**      * @var array of positions      *\/     static protected $positions = [         self::POSITION_HEADER,         self::POSITION_FOOTER,         self::POSITION_LEFT,         self::POSITION_RIGHT,     ];      \/**      * @var string controller name      *\/     public $defaultControllerName = 'DefaultController';      \/**      * @var string dir of modules catalog      *\/     public $modulesDir = 'catalog';      \/**      * @var string modules namespace      *\/     private $_modulesNamespace;      \/**      * @var string absolute path to modules dir      *\/     public $modulePath;      \/**      *      * @throws \\yii\\base\\InvalidParamException      *\/     public function init()     {         parent::init();          $this-&gt;_setModuleVariables();          $this-&gt;loadModules();     }      \/**      * Load modules from directory by path      * @throws \\yii\\base\\InvalidParamException      *\/     protected function loadModules()     {         $handle = opendir($this-&gt;modulePath);          while (($dir = readdir($handle)) !== false) {             if ($dir === '.' || $dir === '..') {                 continue;             }              $class = $this-&gt;_modulesNamespace . '\\\\' . $dir . '\\\\Module';              if (class_exists($class)) {                 $this-&gt;modules = [                     $dir =&gt; [                         'class' =&gt; $class,                     ],                 ];             }         }          closedir($handle);     }      \/**      * @param $layout      * @param array $positions      * @return array      * @throws \\yii\\base\\InvalidConfigException      *\/     public function run($layout, array $positions = [])     {         $model = $this-&gt;findModel($layout, $positions);          $data = [];          foreach ($model as $item) {             if ($controller = $this-&gt;findModuleController($item['module'])) {                 $data[$item['position']][] = \\Yii::createObject($controller, [$item['module'], $this])-&gt;index();             }         }          return $data;     }      \/**      * @param $layout_id      * @param array $positions      * @return array|\\yii\\db\\ActiveRecord[]      * @internal param $layout      *\/     public function findModel($layout_id, array $positions = [])     {         if (empty($positions)) {             $positions = self::$positions;         }          return LayoutModule::find()             -&gt;where([                 'layout_id' =&gt; $layout_id,                 'position' =&gt; $positions,                 'status' =&gt; LayoutModule::STATUS_ACTIVE,             ])-&gt;orderBy([                 'sort_order' =&gt; SORT_ASC             ])-&gt;asArray()-&gt;all();     }      \/**      * @param $name      * @return null|string      *\/     public function findModuleController($name)     {         $className = $this-&gt;_modulesNamespace . '\\\\' . $name . '\\controllers\\\\' . $this-&gt;defaultControllerName;          return is_subclass_of($className, Controller::class) ? $className : null;     }      \/**      * Set modules namespace and path      *\/     private function _setModuleVariables()     {         $class = new \\ReflectionClass($this);         $this-&gt;_modulesNamespace = $class-&gt;getNamespaceName() . '\\\\' . $this-&gt;modulesDir;         $this-&gt;modulePath = dirname($class-&gt;getFileName()) . DIRECTORY_SEPARATOR . $this-&gt;modulesDir;     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0423\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043c\u043e\u0434\u0443\u043b\u044f <b>app\\modules\\dispatcher\\Module<\/b> \u043e\u0442 <b>BasicModule<\/b><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Module.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  namespace app\\modules\\dispatcher;  \/**  * dispatcher module definition class  *\/ class Module extends BasicModule {     \/**      * @inheritdoc      *\/     public function init()     {         parent::init();     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">    public $table = '{{%layout_module}}';      public function safeUp()     {         $tableOptions = null;         if ($this-&gt;db-&gt;driverName === 'mysql') {             $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';         }           $this-&gt;createTable($this-&gt;table, [             'id' =&gt; $this-&gt;primaryKey(),             'layout_id' =&gt; $this-&gt;integer()-&gt;notNull(), \/\/ id \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f             'module' =&gt; $this-&gt;string(150)-&gt;notNull(),  \/\/\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f             'status' =&gt; $this-&gt;boolean()-&gt;defaultValue(true),             'position' =&gt; $this-&gt;string(30)-&gt;notNull(),             'sort_order' =&gt; $this-&gt;integer()-&gt;defaultValue(1),         ], $tableOptions);     }      public function safeDown()     {         $this-&gt;dropTable($this-&gt;table);     } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0417\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<pre><code class=\"sql\">INSERT INTO `layout_module` VALUES ('1', '1', 'test', '1', 'header', '1'); INSERT INTO `layout_module` VALUES ('2', '1', 'test', '1', 'footer', '1'); INSERT INTO `layout_module` VALUES ('3', '1', 'test', '1', 'left', '1'); <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f <b>dispatcher<\/b> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <b>components<\/b>. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <b>Controller<\/b> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c <b>\\yii\\web\\Controller<\/b>. \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0432 \u043d\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <b>render()<\/b>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Controller.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  namespace app\\modules\\dispatcher\\components;  \/**  *  * Class Controller  * @package app\\modules\\dispatcher\\components  *\/ class Controller extends \\yii\\web\\Controller {     \/**      * @param string $view      * @param array $params      * @return string      * @throws \\yii\\base\\InvalidParamException      * @throws \\yii\\base\\ViewNotFoundException      * @throws \\yii\\base\\InvalidCallException      *\/     public function render($view, $params = [])     {         $controller = str_replace('Controller', '', $this-&gt;module-&gt;defaultControllerName);          $path = '@app\/modules\/dispatcher\/' . $this-&gt;module-&gt;modulesDir . '\/' . $this-&gt;id . '\/views\/' . $controller;          return $this-&gt;getView()-&gt;render($path . '\/' . 'index', $params, $this);     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 \u043a\u043e\u0440\u043d\u0435 \u043c\u043e\u0434\u0443\u043b\u044f <b>dispatcher<\/b> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <b>catalog<\/b> \u2014 \u044d\u0442\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439.<\/p>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043d\u0438\u0447\u0435\u043c \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e \u043c\u043e\u0434\u0443\u043b\u044f <b>Yii2<\/b>. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <b>test<\/b>, \u0432 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <b>Module<\/b>:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Module.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace app\\modules\\dispatcher\\catalog\\test;  \/**  * test module definition class  *\/ class Module extends \\yii\\base\\Module {     \/**      * @inheritdoc      *\/     public $controllerNamespace = 'app\\modules\\dispatcher\\catalog\\test\\controllers'; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <b>controllers<\/b> \u0438 \u0432 \u043d\u0435\u0439 \u043a\u043b\u0430\u0441\u0441 <b>DefaultController<\/b> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e <b>app\\modules\\dispatcher\\components\\Controller<\/b>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">DefaultController.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  namespace app\\modules\\dispatcher\\catalog\\test\\controllers;  use app\\modules\\dispatcher\\components\\Controller;  \/**  * Default controller for the `test` module  *\/ class DefaultController extends Controller {     \/**      * Renders the index view for the module      * @return string      * @throws \\yii\\base\\InvalidParamException      * @throws \\yii\\base\\ViewNotFoundException      * @throws \\yii\\base\\InvalidCallException      *\/     public function index()     {         return $this-&gt;render('index');     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <i>\u0412\u0430\u0436\u043d\u043e: \u0447\u0442\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043d\u0430\u0448 \u043c\u043e\u0434\u0443\u043b\u044c \u043e\u043d \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 <b>app\\modules\\dispatcher\\components\\Controller<\/b> \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <b>index<\/b><\/i><\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f <b>views\/default<\/b> \u0438 \u0444\u0430\u0439\u043b \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">index.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;div class=&quot;dispatcher-default-index&quot;&gt;     &lt;p&gt;         You may customize this page by editing the following file:&lt;br&gt;         &lt;code&gt;&lt;?= __FILE__ ?&gt;&lt;\/code&gt;     &lt;\/p&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043d\u0430\u0448\u0438\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <b>Dispatcher<\/b> \u0432 <b>app\\modules\\dispatcher\\components<\/b>:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Dispatcher.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  namespace app\\modules\\dispatcher\\components;  use yii\\base\\Object;  class Dispatcher extends Object {     \/**      * @var \\app\\modules\\dispatcher\\Module      *\/     private $_module;      public $module = 'dispatcher';      \/**      * Dispatcher constructor.      * @param array $config      *\/     public function __construct(array $config = [])     {         parent::__construct($config);          $this-&gt;_module = \\Yii::$app-&gt;getModule($this-&gt;module);     }      \/**      * Get modules by layout      *      * @param $layout      * @param array $positions      * @return array      * @throws \\yii\\base\\InvalidConfigException      *\/     public function modules($layout, array $positions = [])     {         return $this-&gt;_module-&gt;run($layout, $positions);     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 <b>web.php<\/b><\/p>\n<pre><code class=\"php\">        'dispatcher' =&gt; [             'class' =&gt; 'app\\modules\\dispatcher\\components\\Dispatcher',         ], <\/code><\/pre>\n<p>  <i>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 <b>components<\/b>.<\/i><\/p>\n<p>  \u0412 \u043b\u044e\u0431\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <b>SiteController<\/b>, \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <b>actionIndex()<\/b> \u0434\u043e\u0431\u0430\u0432\u0438\u043c<\/p>\n<pre><code class=\"php\">\t\/* @var $modules Dispatcher *\/ \t$modules = \\Yii::$app-&gt;dispatcher-&gt;modules(1);  \treturn $this-&gt;render('index', compact('modules')); <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 <b>views\/site\/index.php<\/b>:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">index.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  \/* @var $this yii\\web\\View *\/  $this-&gt;title = 'My Yii Application';  use app\\modules\\dispatcher\\Module;  ?&gt; &lt;div class=&quot;site-index&quot;&gt;      &lt;?php if (isset($modules[Module::POSITION_HEADER])) { ?&gt;         &lt;div class=&quot;row&quot;&gt;             &lt;?php foreach ($modules[Module::POSITION_HEADER] as $module) {                 echo $module;             } ?&gt;         &lt;\/div&gt;     &lt;?php } ?&gt;       &lt;div class=&quot;jumbotron&quot;&gt;         &lt;h1&gt;Congratulations!&lt;\/h1&gt;          &lt;p class=&quot;lead&quot;&gt;You have successfully created your Yii-powered application.&lt;\/p&gt;          &lt;p&gt;&lt;a class=&quot;btn btn-lg btn-success&quot; href=&quot;http:\/\/www.yiiframework.com&quot;&gt;Get started with Yii&lt;\/a&gt;&lt;\/p&gt;     &lt;\/div&gt;      &lt;div class=&quot;body-content&quot;&gt;          &lt;div class=&quot;row&quot;&gt;             &lt;div class=&quot;col-lg-4&quot;&gt;                 &lt;h2&gt;Heading&lt;\/h2&gt;                  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor                     incididunt ut                     labore et                     dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris                     nisi                     ut aliquip                     ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse                     cillum dolore eu                     fugiat nulla pariatur.&lt;\/p&gt;                  &lt;p&gt;&lt;a class=&quot;btn btn-default&quot; href=&quot;http:\/\/www.yiiframework.com\/doc\/&quot;&gt;Yii                         Documentation &raquo;&lt;\/a&gt;&lt;\/p&gt;             &lt;\/div&gt;             &lt;div class=&quot;col-lg-4&quot;&gt;                 &lt;h2&gt;Heading&lt;\/h2&gt;                  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor                     incididunt ut                     labore et                     dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris                     nisi                     ut aliquip                     ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse                     cillum dolore eu                     fugiat nulla pariatur.&lt;\/p&gt;                  &lt;p&gt;&lt;a class=&quot;btn btn-default&quot; href=&quot;http:\/\/www.yiiframework.com\/forum\/&quot;&gt;Yii                         Forum &raquo;&lt;\/a&gt;                 &lt;\/p&gt;             &lt;\/div&gt;             &lt;div class=&quot;col-lg-4&quot;&gt;                 &lt;h2&gt;Heading&lt;\/h2&gt;                  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor                     incididunt ut                     labore et                     dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris                     nisi                     ut aliquip                     ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse                     cillum dolore eu                     fugiat nulla pariatur.&lt;\/p&gt;                  &lt;p&gt;&lt;a class=&quot;btn btn-default&quot; href=&quot;http:\/\/www.yiiframework.com\/extensions\/&quot;&gt;Yii                         Extensions &raquo;&lt;\/a&gt;&lt;\/p&gt;             &lt;\/div&gt;         &lt;\/div&gt;     &lt;\/div&gt;      &lt;?php if (isset($modules[Module::POSITION_FOOTER])) { ?&gt;         &lt;div class=&quot;row&quot;&gt;             &lt;?php foreach ($modules[Module::POSITION_FOOTER] as $module) {                 echo $module;             } ?&gt;         &lt;\/div&gt;     &lt;?php } ?&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e <a href=\"https:\/\/github.com\/yiisoft\/yii2\/blob\/master\/docs\/guide-ru\/structure-modules.md\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044f\u043c<\/a>.<\/p>\n<p>  \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u044b\u043b\u043e\u0436\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/blessedness\/yii2-modules-dispatcher\">GitHub<\/a>.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/317950\/\"> https:\/\/habrahabr.ru\/post\/317950\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0441\u0435\u0445! \u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Yii2 \u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u043a\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0434\u0443\u043b\u044c. <\/p>\n<p>  \u0412 Yii2 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0438\u043d\u0443\u0441 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u0442.\u043a. \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0430 \u0438 \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 POST-\u0437\u0430\u043f\u0440\u043e\u0441 (\u0445\u043e\u0442\u044f \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u0438\u0434\u0436\u0435\u0442\u044b \u0442\u0430\u043a \u0441 \u043d\u0435\u043a\u0438\u043c\u0438 \u043a\u043e\u0441\u0442\u044b\u043b\u044f\u043c\u0438).  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-282708","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282708"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282708\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}