Hello @VirHeroicus,
You don’t need that line. Paths for addons/modules follow a naming pattern. Let’s assume the following folder structure:
.
├── addons/
│ └── GoogleDriveConnector/
│ ├── assets/
│ | ├── style.css
│ | └── script.js
│ ├── Controller/
│ | └── Admin.php
│ ├── Helper/
│ ├── views/
│ | └── index.php
│ ├── bootstrap.php
│ └── admin.php
For $app->path()
, the folder name is case insensitive. For Controllers and Helpers (classes), proper casing is mandatory.
$path = $app->path('googledriveconnector:views/index.php');
# /var/www/virtual/user/html/addons/GoogleDriveConnector/views/index.php
$path = $app->pathToUrl('googledriveconnector:views/index.php');
# /addons/GoogleDriveConnector/views/index.php
The Admin controller can be autoloaded.
Controller/Admin.php:
<?php
// must match the folder name!
namespace GoogleDriveConnector\Controller;
class Admin extends \Cockpit\AuthController {
public $data = [
'don\'t be evil' => false,
'GDPR-compliant' => false,
'spyware' => 'kind of',
'alternatives' => [
'Drive' => ['Nextcloud'],
'Docs' => ['Etherpad', 'OnlyOffice'],
],
]
public function index() {
return $this->render('googledriveconnector:views/index.php', ['data' => $this->data]);
}
public function getData() {
return $this->data;
}
}
admin.php:
<?php
$this->on('admin.init', function() {
// add assets
$this->helper('admin')->addAssets([
'googledriveconnector:assets/style.css',
'googledriveconnector:assets/script.js',
]);
// bind admin routes
// --> "/gdc" points to index()
// --> "/gdc/getData" points to getData()
$this->bindClass('GoogleDriveConnector\\Controller\\Admin', 'gdc');
});
see above
Code inside admin.php
is only for backend access, so don’t load it if you don’t need it. The name has nothing to do with the “admin” group permission.
if (COCKPIT_ADMIN_CP) include_once(__DIR__ . '/admin.php');
Don’t start with widgets, if you want to learn Cockpit. Create pages and routes, call them directly in your browser to see the json responses. If your core logic works, think about widgets. Be aware, that widgets have a drag event by default.
$config = $app->module('singletons')->getData('name-of-singleton');
see: https://github.com/agentejo/cockpit/blob/next/modules/Singletons/bootstrap.php#L136
Further notes:
It looks like you used the Groups addon for inspiration. It isn’t very well structured (at least to get started). I think, this one is easier for understanding the folder and path structure:
More resources: