/** * Creates a new Product model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = Yii::createObject(Product::className()); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Bootstrap method to be called during application bootstrap stage. * @param Application $app the application currently running */ public function bootstrap($app) { $module = $app->getModule('product'); $class = Product::className(); $definition = $class; /** @var Module $module */ if ($module !== null && !empty($module->productModel)) { $definition = $module->productModel; } \Yii::$container->set($class, $definition); $className = is_array($definition) ? $definition['class'] : $definition; \Yii::$container->set(ProductQuery::className(), function () use($className) { return $className::find(); }); Event::on(ProductQuery::className(), ProductQuery::EVENT_INIT, function (Event $e) use($class, $className) { if ($e->sender->modelClass == $class) { $e->sender->modelClass = $className; } }); }