@BernhardPosselt Could my problem be solved with automated DI too?
What exactly is the difference, where do I find documentation?
It seems, that the tutorial is completely broken!
@BernhardPosselt Could my problem be solved with automated DI too?
What exactly is the difference, where do I find documentation?
It seems, that the tutorial is completely broken!
Solution
For the records, for others with the same problem, what @Cult did, the relevant changes are:
remove appinfo/autoload.php
remove <navigations />
from appinfo/info.xml
in lib/Db/GeschaeftMapper.php
replace deprecated IDb
by OC\DB\Connection
:
…
use OC\DB\Connection;
…
public function __construct(Connection $db) {
…
change appinfo/app.php
to:
<?php
namespace OCA\GgrWinti\AppInfo;
use OCP\AppFramework\App;
$app = new Application();
$app->registerNavigation();
added a new lib/AppInfo/Application.php
:
<?php
namespace OCA\GgrWinti\AppInfo;
use OCA\GgrWinti\Controller\GeschaeftController;
use OCA\GgrWinti\Controller\PageController;
use OCA\GgrWinti\Db\GeschaeftMapper;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
class Application extends App {
/** @var string */
private $appName;
/**
* @param array $params
*/
public function __construct(array $params = array()) {
parent::__construct('ggrwinti', $params);
$container = $this->getContainer();
$this->appName = $container->query('AppName');
self::registerControllers($container);
self::registerMappers($container);
self::registerCores($container);
// Translates
// $container->registerService(
// 'L10N', function(IAppContainer $c) {
// return $c->query('ServerContainer')
// ->getL10N($c->query('AppName'));
// }
// );
}
/**
* Register Controllers
*
* @param $container
*/
private static function registerControllers(IAppContainer &$container) {
$container->registerService(
'PageController', function(IAppContainer $c) {
return new PageController(
$c->query('AppName'), $c->query('Request'), $c->query('UserId')
);
}
);
$container->registerService(
'GeschaeftController', function(IAppContainer $c) {
return new GeschaeftController(
$c->query('AppName'), $c->query('Request'), $c->query('GeschaeftMapper'),
$c->query('UserId')
);
}
);
}
/**
* Register Mappers
*
* @param $container
*/
private static function registerMappers(IAppContainer &$container) {
$container->registerService(
'GeschaeftMapper', function(IAppContainer $c) {
return new GeschaeftMapper(
$c->query('ServerContainer')
->getDatabaseConnection()
);
}
);
}
/**
* Register Cores
*
* @param $container
*/
private static function registerCores(IAppContainer &$container) {
$container->registerService(
'UserId', function(IAppContainer $c) {
$user = $c->query('ServerContainer')
->getUserSession()
->getUser();
/** @noinspection PhpUndefinedMethodInspection */
return is_null($user) ? '' : $user->getUID();
}
);
}
/**
* Register Navigation Tab
*/
public function registerNavigation() {
$this->getContainer()
->getServer()
->getNavigationManager()
->add(
function() {
$urlGen = \OC::$server->getURLGenerator();
return [
'id' => $this->appName,
'order' => 10,
'href' => $urlGen->linkToRoute('ggrwinti.page.index'),
'icon' => $urlGen->imagePath($this->appName, 'app.svg'),
'name' => 'GGR-Winti'
];
}
);
}
//
// public function registerSettingsAdmin() {
// \OCP\App::registerAdmin(
// $this->getContainer()
// ->query('AppName'), 'lib/admin'
// );
// }
}
Open Questions:
lib/AppInfo/Application.php
?appinfo
and lib/AppInfo
, is the first one deprecated, should everything be moved to the second?Thank you, @Cult for your help!
First, report this problem to the bug tracker: Issues · nextcloud/documentation · GitHub
If you want, you can start to work on a better version …
see:
I’ve forked and updated https://github.com/nextcloud/app-tutorial but running into this issue https://github.com/nextcloud/server/issues/5929
I will however not update the docs so someone else will need to copy back the files
Ok, ran into the same issue when porting, it’s a bug which probably ended up in there because of container refactorings in 12. Please file an issue in the server repo https://github.com/nextcloud/server/issues/
FYI you can also link https://github.com/nextcloud/app-tutorial in your bug report which has the same issue
Ok, https://github.com/nextcloud/app-tutorial shoudl be up to date now. The error that you’ve encountered is a broken error message because IDb does not exist anymore.
IMPORTANT: this tutorial is not yet present in the docs, so someone has to copy paste over the new stuff. I need your help here
Thanks @BernhardPosselt!
I just started developing an app for NextCloud and I was already highly frustrated that the tutorial app doesn’ work—even the demo code provided on GitHub! This is really a bad first expierence! I also looked at the code of other apps and wondered why they do things differently from the tutorial (and probably “best practice”) app.
Just for the record: I started my app over a few times and always ran to the “Could not resolve AppName! Class AppName does not exist” error without any clue why:
{
"reqId": "bGW7I9HP0NfqaBFLKO7v",
"level": 3,
"time": "2017-09-20T07:27:54+00:00",
"remoteAddr": "127.0.0.1",
"user": "foobar",
"app": "index",
"method": "GET",
"url": "\/portal\/index.php\/apps\/foobar_test\/profiles",
"message": "Exception: {\"Exception\":\"OCP\\\\AppFramework\\\\QueryException\",\"Message\":\"Could not resolve AppName! Class AppName does not exist\",\"Code\":0,\"Trace\":\"#0 \\\ ... }",
"userAgent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko\/20100101 Firefox\/55.0",
"version": "12.0.2.0"
}
(Note: I truncated the trace in the exception.)
The tutorial should be updated quickly!
What do you mean by “code doesnt work”? The app tutorial github repo should work with Nextcloud 12
The code of the GitHub repo linked in the tutorial doesn’t work: https://github.com/owncloud/app-tutorial#tutorial
I just now realized that the link goes to the ownCloud repo and not the NextCloud repo—before I just wondered, that the last changes where made about three years ago.
So, it’s even worse that the tutorial links to the wrong and old demo code.
Yeah, docs are totally outdated and no one cares.
I care, as a reader of the outdated docs…!
The project leaders should really care about keeping the docs up to date, this also is an important job. It helps in creating and maintaining cool apps!