Exemplo n.º 1
0
 /**
  * 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;
         }
     });
 }
Exemplo n.º 2
0
 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }