Skip to content

Instantly share code, notes, and snippets.

@rufinus
Created December 11, 2012 13:33
Show Gist options
  • Select an option

  • Save rufinus/4258599 to your computer and use it in GitHub Desktop.

Select an option

Save rufinus/4258599 to your computer and use it in GitHub Desktop.
Redirect if not loged in
return array(
'controllers' => array(
'initializers' => array(
function ($instance, $serviceManager) {
if ($instance instanceof NeedLoginAwareInterface) {
$auth = $serviceManager->getServiceLocator()->get('cwdAdmin.auth_service');
if(!$auth->hasIdentity()) {
//$instance->redirect()->toUrl('/admin/auth/login');
header('Location: /auth/login');
exit;
}
}
}
)
)
);
class MyController extends Controller implements NeedLoginAwareInterface
{
public function indexAction()
{
// only displayed if we have an identity
}
}
namespace Foo;
interface NeedLoginAwareInterface
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment