Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1068

Joomla! 4.x Coding • Am I doing something stupid?

$
0
0
I thought I'd figured out how this namespacing works, but apparently not.

I have a component with this model:

administrator/components/com_example/src/Model/FlowsModel.php

Code:

namespace Acme\Component\Example\Administrator\Model;use Joomla\CMS\MVC\Model\ListModel;class FlowsModel extends ListModel{       public function copyflows($ids)    {           return 'success';    }}
My Controller looks like this:

administrator/components/com_example/src/Controller/FlowsController.php

Code:

namespace Acme\Component\Example\Administrator\Controller;use Joomla\CMS\MVC\Controller\AdminController;class FlowsController extends AdminController{    public function copyflows()    {           // Get the input        $pks = $this->input->post->get('cid', array(), 'array');        $pks = ArrayHelper::toInteger($pks);        // Get the model        $model = $this->getModel('Flows', 'Administrator');        // Check if the model exists and call the copyflows method        if ($model)            $msg = $model->copyflows($pks);         else            $msg = 'Model not found';// <<<<< THIS MESSAGE IS DISPLAYED        Factory::getApplication()->enqueueMessage($msg, 'notice');        $this->setRedirect(Route::_('index.php?option=com_example&view=flows', false));    }}
When I run the code I get "Model not found" message, so $this->getModel('Flows', 'Administrator'); is not finding the model. I don't understand why, maybe I'm fundamentally misunderstanding how this is supposed to work.

Any ideas very welcome :)

Statistics: Posted by david0058 — Tue Dec 31, 2024 5:16 pm



Viewing all articles
Browse latest Browse all 1068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>