In a controller, I am trying to load the model, but I have the following error:
Call to a member function getSearchURL() on bool
So the getModel()
is returning false
. This is the code of my controller, MycomponentController
just extend BaseController
:
namespace Example\Mycomponent\Site\Controllers;
class SearchController extends MycomponentController
{
public function __construct($config = [])
{
parent::__construct($config);
}
public function results()
{
$model = $this->getModel('Search');
$this->setRedirect(
$model->getSearchURL(
'search',
$model->getState('searchwords'),
$model->getState('list.start'),
$model->getState('list.limit'),
$model->getUrlParams(),
false
)
);
}
}
The class MycomponentController is the following :
namespace Example\Mycomponent\Libraries\Controller;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
class MycomponentController extends BaseController
{
public function __construct($config = [], MVCFactoryInterface $factory = null, $app = null, $input = null)
{
$this->app = Factory::getApplication();
if (empty($this->input))
{
$this->input = $this->app->input;
}
parent::__construct($config, $factory, $app, $input);
}
}
The model is named SearchModel.php and is the following:
namespace Example\Mycomponent\Site\Model;
class SearchModel extends MycomponentModel
{
public function getSearchURL($view, $searchword = '', $limitstart = 0, $limit = 0, $params = '', $xhtml = true)
{
}
}
So why is the controller unable to find the model?
P.S.: I have found that it goes to Joomla\CMS\MVC\Factory\LegacyFactory::createModel() then her it call Joomla\CMS\MVC\Model\LegacyModelLoaderTrait::getInstance() but here it doesn't loads by namespace but by old way, because the Joomla\CMS\MVC\Model\LegacyModelLoaderTrait::getInstance() clean all the namepsapce by removing the \