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;
}