title: Zf2 layout and authentication
body: <p>I am building a ZF2 based site, and it has 2 different layouts. It has some public pages and some internal pages which require user authentication, each set of pages have their layouts. I was initially thinking of creating a controller plugin and check if the user has identity then I will change the layout, but it would also change the layout of public pages for a logged in user, which we don't want. Also I don't know how to change the layout from a controller plugin. </p>
  
  <p>The layout of internal pages also require some information regarding the current users and some other information from other tables. So I was thinking of creating another plugin which will check if the user has identity and thn it will set the layout variables. I am not sure how to get the layout object in the controller plugin to set variables. Also don't know how to get one plugin access other plugin. </p>
  
  <p>Also for the internal pages I am checking in every action if the user is logged in or not. If he has no identity, I am sending him to login page. This resulted in lots of repeating code, so is there a way to move this code to a controller plugin, and some-how tell it to check user's identity on specific pages and if user has identity let him access the page otherwise send him to login screen.</p>