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

Joomla! 4.x Coding • Problem finding models

$
0
0
I'm climbing the vertical learning curve of converting a J3.x component to J4.0, and the whole area of namespacing and service registration is a @£%@£%£$. I appreciate the benefits, I just can't see how to make it work.

I'm trying to construct a minimal backend component with a list view ('Folders') and an item add/edit view ('Folder'). I *think* everything is in the right place: my source directory structure is below.

Code:

.├── com_conlucra_chat│   ├── administrator│   │   ├── LICENSE.txt│   │   ├── access.xml│   │   ├── config.xml│   │   ├── forms│   │   │   ├── filter_folders.xml│   │   │   ├── folder.xml│   │   │   └── index.html│   │   ├── index.html│   │   ├── language│   │   │   ├── en-GB│   │   │   │   ├── en-GB.com_conlucra_chat.ini│   │   │   │   ├── en-GB.com_conlucra_chat.sys.ini│   │   │   │   └── index.html│   │   │   └── index.html│   │   ├── services│   │   │   ├── index.html│   │   │   └── provider.php│   │   ├── sql│   │   │   ├── index.html│   │   │   ├── install.mysql.utf8.sql│   │   │   ├── uninstall.mysql.utf8.sql│   │   │   └── updates│   │   │       ├── index.html│   │   │       └── mysql│   │   │           ├── 1.0.sql│   │   │           └── index.html│   │   ├── src│   │   │   ├── Controller│   │   │   │   ├── DisplayController.php│   │   │   │   ├── FolderController.php│   │   │   │   └── FoldersController.php│   │   │   ├── Helper│   │   │   │   ├── ChatHelper.php│   │   │   │   ├── DeleteHelper.php│   │   │   │   ├── PermissionsHelper.php│   │   │   │   └── index.html│   │   │   ├── Model│   │   │   │   ├── FolderModel.php│   │   │   │   └── FoldersModel.php│   │   │   ├── Table│   │   │   │   └── FolderTable.php│   │   │   └── View│   │   │       ├── Folder│   │   │       │   └── HtmlView.php│   │   │       └── Folders│   │   │           └── HtmlView.php│   │   └── tmpl│   │       ├── folder│   │       │   ├── edit.php│   │       │   └── index.html│   │       └── folders│   │           ├── default.php│   │           ├── default.xml│   │           └── index.html│   ├── com_conlucra_chat.xml│   ├── com_conlucra_chat_install.php│   ├── index.html│   └── media│       ├── attention.png├── com_conlucra_chat_update.xml└── index.html
I've replaced the front controller (controller.php) and component entry point file with a services/provider.php, and I think all my namespacing is correct - I've read all the files many times.

However, while the list view is working, and shows all the records in the folder table, the item view is not. I get an error "Call to a member function getTable() on bool", which suggests that Joomla is not finding the Model/FolderModel class.

I know that the get ListQuery() function in FoldersModel is being called, so I put this code in there:

Code:

 $model = $this->getMVCFactory()->createModel('Folder', 'Administrator');file_put_contents('/tmp/debug.log', Factory::getDate()->toSql() . ': got folder model ' . var_export($model, true) . PHP_EOL, FILE_APPEND);$model = $this->getMVCFactory()->createModel('Folders', 'Administrator');file_put_contents('/tmp/debug.log', Factory::getDate()->toSql() . ': got folders model ' . var_export($model, true) . PHP_EOL, FILE_APPEND);
In each case, $model is false, so now I don't know if Joomla is finding *any* of my models (though it must be, as otherwise how would it find the getListQuery() function?).

I put this constructor in my FolderModel class:

Code:

namespace Conlucra\Component\Chat\Administrator\Model;use Joomla\CMS\Factory;use Joomla\CMS\Language\Text;use Joomla\CMS\MVC\Model\AdminModel;use Joomla\CMS\Table\Table;use Joomla\CMS\Versioning\VersionableModelTrait;use Joomla\Database\DatabaseDriver;use Joomla\Database\Exception\DatabaseExceptionInterface;use Joomla\Utilities\ArrayHelper;use Conlucra\Component\Chat\Administrator\Helper\PermissionsHelper;defined('_JEXEC') or die;class FolderModel extends AdminModel{    use VersionableModelTrait;        public function __construct($config = [])    {           file_put_contents('/tmp/debug.log', 'FolderModel instantiated' . PHP_EOL, FILE_APPEND);        parent::__construct($config);    }...
and it never seems to get called, adding to my suspicion that the FolderModel is not being found.

Any clues?

Statistics: Posted by david0058 — Sun Dec 22, 2024 12:54 pm



Viewing all articles
Browse latest Browse all 1040

Trending Articles



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