Пример #1
0
 public function execute()
 {
     // Backend or frontend?
     $section = $this->input->get('frontend', false) ? 'site' : 'admin';
     $view = $this->getViewName($this->input);
     // Let's force the use of the Magic Factory
     $container = Container::getInstance($this->component, array('factoryClass' => 'FOF30\\Factory\\MagicFactory'));
     $container->factory->setSaveScaffolding(true);
     $view = $container->inflector->pluralize($view);
     $classname = $container->getNamespacePrefix($section) . 'Model\\' . ucfirst($view);
     $scaffolding = new ModelBuilder($container);
     $scaffolding->setSection($section);
     if (!$scaffolding->make($classname, $view)) {
         throw new \RuntimeException("An error occurred while creating the Model class");
     }
 }
Пример #2
0
 /**
  * Create a new Model object
  *
  * @param   string  $viewName  The name of the view we're getting a Model for.
  * @param   array   $config    Optional MVC configuration values for the Model object.
  *
  * @return  Model
  */
 public function model($viewName, array $config = array())
 {
     $modelClass = $this->container->getNamespacePrefix($this->getSection()) . 'Model\\' . ucfirst($viewName);
     try {
         return $this->createModel($modelClass, $config);
     } catch (ModelNotFound $e) {
     }
     $modelClass = $this->container->getNamespacePrefix($this->getSection()) . 'Model\\' . ucfirst($this->container->inflector->singularize($viewName));
     try {
         $model = $this->createModel($modelClass, $config);
     } catch (ModelNotFound $e) {
         // Do I have to create and save the class file? If not, let's rethrow the exception
         if (!$this->saveModelScaffolding) {
             throw $e;
         }
         // By default model classes are plural
         $modelClass = $this->container->getNamespacePrefix($this->getSection()) . 'Model\\' . ucfirst($viewName);
         $scaffolding = new ModelBuilder($this->container);
         // Was the scaffolding successful? If so let's call ourself again, otherwise throw a not found exception
         if ($scaffolding->make($modelClass, $viewName)) {
             $model = $this->model($viewName, $config);
         } else {
             throw $e;
         }
     }
     return $model;
 }