diff --git a/libraries/src/MVC/Controller/BaseController.php b/libraries/src/MVC/Controller/BaseController.php index cad677f3e904f..d7a41a06bfe68 100644 --- a/libraries/src/MVC/Controller/BaseController.php +++ b/libraries/src/MVC/Controller/BaseController.php @@ -580,11 +580,6 @@ protected function checkEditId($context, $id) */ protected function createModel($name, $prefix = '', $config = array()) { - if (!$prefix) - { - $prefix = $this->app->getName(); - } - $model = $this->factory->createModel($name, $prefix, $config); if ($model === null) @@ -615,11 +610,6 @@ protected function createModel($name, $prefix = '', $config = array()) */ protected function createView($name, $prefix = '', $type = '', $config = array()) { - if (!$prefix) - { - $prefix = $this->app->getName(); - } - $config['paths'] = $this->paths['view']; return $this->factory->createView($name, $prefix, $type, $config); } @@ -755,9 +745,21 @@ public function getModel($name = '', $prefix = '', $config = array()) $name = $this->getName(); } - if (empty($prefix) && $this->factory instanceof LegacyFactory) + if (!$prefix) { - $prefix = $this->model_prefix; + if ($this->factory instanceof LegacyFactory) + { + $prefix = $this->model_prefix; + } + // When the frontend uses an administrator model + elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0) + { + $prefix = 'Administrator'; + } + else + { + $prefix = $this->app->getName(); + } } if ($model = $this->createModel($name, $prefix, $config)) @@ -865,9 +867,21 @@ public function getView($name = '', $type = '', $prefix = '', $config = array()) $name = $this->getName(); } - if (empty($prefix) && $this->factory instanceof LegacyFactory) + if (!$prefix) { - $prefix = $this->getName() . 'View'; + if ($this->factory instanceof LegacyFactory) + { + $prefix = $this->getName() . 'View'; + } + // When the front uses an administrator view + elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0) + { + $prefix = 'Administrator'; + } + else + { + $prefix = $this->app->getName(); + } } if (empty(self::$views[$name][$type][$prefix])) diff --git a/libraries/src/MVC/Factory/MVCFactory.php b/libraries/src/MVC/Factory/MVCFactory.php index 3edd373bc28d7..bb484b0c27a13 100644 --- a/libraries/src/MVC/Factory/MVCFactory.php +++ b/libraries/src/MVC/Factory/MVCFactory.php @@ -98,12 +98,6 @@ public function createModel($name, $prefix = '', array $config = []) $name = preg_replace('/[^A-Z0-9_]/i', '', $name); $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix); - // When the front uses a back end model - if (!$prefix && !empty($config['base_path']) && strpos($config['base_path'], '/administrator/') !== false) - { - $prefix = 'Administrator'; - } - if (!$prefix) { @trigger_error( @@ -150,12 +144,6 @@ public function createView($name, $prefix = '', $type = '', array $config = []) $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix); $type = preg_replace('/[^A-Z0-9_]/i', '', $type); - // When the front uses a back end view - if (!$prefix && !empty($config['base_path']) && strpos($config['base_path'], '/administrator/') !== false) - { - $prefix = 'Administrator'; - } - if (!$prefix) { @trigger_error(