FOF30\Factory\BasicFactory::model PHP Method

model() public method

Create a new Model object
public model ( string $viewName, array $config = [] ) : Model
$viewName string The name of the view we're getting a Model for.
$config array Optional MVC configuration values for the Model object.
return FOF30\Model\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;
    }

Usage Example

Esempio n. 1
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())
 {
     try {
         return parent::model($viewName, $config);
     } catch (ModelNotFound $e) {
         $magic = new Magic\ModelFactory($this->container);
         return $magic->make($viewName, $config);
     }
 }
All Usage Examples Of FOF30\Factory\BasicFactory::model