I'm developing a system for a restaurant and every time someone connects to the restaurant's network, a menu tab must pop up. I tried this by detecting the user's IP address and seeing if it matched the restaurant's network. But it doesn't work at all. (All codes must use Yii2, this is my first contact, no experience)
I checked all the folder and file names but they are all correct and the event is not running at all.
Just to provide some background information, I have a component that does the instrumentation work, and all the code is run in that file. The problem seems to be in the actual controller.
<?php namespace app\controllers; use Yii; use yii\web\Controller; class NetworkController extends Controller{ public function actionNetworkTeste(){ Yii::$app->networkEventManager->on('specificNetworkConnectionDetected', [$this, 'onSpecificNetworkConnectionDetected']); return $this->render('networkTeste'); } public function onSpecificNetworkConnectionDetected($event){ //Yii::debug('Funcionou'); return $this->render('network-alt'); } } ?>
I don't even know if this is the right way to do it, popping up a tab when someone is connected to the network, but it's better than not trying at all. I would really appreciate some help as I have no experience with Yii2.
You should read the section on Handling requests
on the Yii2 documentationTo get the client's IP, the document is here, and the request API document is here