Hi,
I’m currently building a helper class for my menu. It is important that I know whether the page I clicked on in the menu is the right one. Because if so, I can then add a css class.
Example:
I have a menu pointing to http://localhost/shop/view/1. Now I would like to read out the controller, the action and, if necessary, all other parameters. I also have some zsm. tinkered, but that doesn’t work. Can someone help me there?
...
use Cake\Http\ServerRequest;
use Cake\View\Helper;
use Cake\Routing\Router;
....
public function isCurentActive( $url ) {
$request = new ServerRequest( array('url' => $url) );
$route = Router::parseRequest( $request );
$controller = $route['controller'];
$action = $route['action'];
$request = Router::getRequest();
$actualController = $request->getParam( 'controller' );
$actualAction = $request->getParam( 'action' );
$actualPassedArgs = $request->getParam( 'pass' );
return ($actualController === $controller) && ($actualAction === $action);
}