Session and how to set login redirect based on role


  1. how do I get the Session to work, I have read the tutorial but I don’t know how to actually get the session to load and start so I can do something like the following when someone logs in.
    Welcome {username}

  2. now I have got login working going to the home page once logged in, while working through the CMS tutorial and wondering how I can redirect user based on a role type based on the below code?

      $this->request->allowMethod(['get', 'post']);
               $result = $this->Authentication->getResult();
              // regardless of POST or GET, redirect if user is logged in
                  if ($result->isValid()) {
             // redirect to /articles after login success
                  $redirect = $this->request->getQuery('redirect', [
                              'controller' => 'Articles',
                               'action' => 'index',
              return $this->redirect($redirect);
                // display error if user submitted and authentication failed
               if ($this->request->is('post') && !$result->isValid()) {
              $this->Flash->error(__('Invalid username or password'));

In my users table I have a field called role so something like the following?


    $redirect = $this->request->getQuery('redirect', [
                        'controller' => 'Members',
                        'action' => 'index', 


 $redirect = $this->request->getQuery('redirect', [
                        'controller' => 'Partners',
                        'action' => 'index',

Super Admin

   $redirect = $this->request->getQuery('redirect', [
                        'controller' => 'Admin',
                        'action' => 'index',
           public function login() {

dunno whats happened with post styling tried to wrap the code
Thanks in advance