Hi,
I’m new and I could register my settingscontroller, but I can’t access \OC::$server. I thought it would be static but it isn’t? Because this: does nothing:
\OC::$server->getLogger()->info("Saved: " . “lalala”, array(“app” => $this->appName));
How can I access \OC::$server?
Thank you for the help.
Greetings,
Björn
Rello
September 21, 2018, 3:17pm
2
do (in the correct sections)
use OCP\ILogger;
private $logger;
ILogger $logger,
$this->logger = $logger;
$this->logger->debug( "Saved: " . “lalala”, array(“app” => $this->appName));
safe your stuff with the ::$server and make it reusable
Ok, can I just extend the constructor like this and I will get what I need, or do I have to register the controller with this special constrcfutor?
I got it by myself and in the context I need it. I just register my controller with the app-container and let nextcloud fill the values for my constructor.
class Application extends App {
public function __construct(array $urlParams=array()){
parent::__construct('mattermostwebhook', $urlParams);
$container = $this->getContainer();
/**
* Controllers
*/
$container->registerService('SettingsController', function($c) {
return new SettingsController(
$c->query('AppName'),
$c->query('Request'),
$c->query('Logger'),
$c->query('Config'),
$c->query('UserID')
);
});
$container->registerService('Logger', function($c) {
return $c->query('ServerContainer')->getLogger();
});
$container->registerService('Config', function($c) {
return $c->query('ServerContainer')->getConfig();
});
$container->registerService('UserID', function($c) {
return $c->query('UserSession')->getUser()->getUID();
});
}
}
for all of you, who want to control this:
<?php throw new \Exception( "\$user = $user" );
this will be logged under settings->log
and values will be saved in the table “oc_preferences” with username and AppID.