Witam,
od paru dni walczę z zf2, no i napotkałem na pewien (w teorii) banalny problem:
W skrócie o aplikacji:
IndexController <- sprawdza czy sesja istnieje jeżeli nie to wywołuje inny kontroler w zależności od wyniku
AuthUserController <- odpowiada za wszelkie działania związane z logowaniem ( w przypadku braku sesji)

Chcę by w sytuacji braku sesji wywoływało template z pliku view/creator/authUser/index.phtml (klasa AuthUserController, metoda indexAction)

Problem:
Nie wyświetla owego pliku, także nie wyrzuca żadnych błędów.

Proszę o napisanie gdzie leży mój błąd oraz ew. jak możnaby go rozwiązać.


Struktura:


Zawartość plików:
config/module.config.php
  1. <?php
  2.  
  3. return array(
  4.  
  5. 'controllers' => array(
  6. 'invokables' => array(
  7. 'Creator\Controller\Index' => 'Creator\Controller\IndexController',
  8. 'Creator\Controller\AuthUser' => 'Creator\Controller\AuthUser',
  9. ),
  10. ),
  11.  
  12. 'router' => array(
  13. 'routes' => array(
  14. 'creator' => array(
  15. 'type' => 'segment',
  16. 'options' => array(
  17. 'route' => '/creator[/:action][/:id]',
  18. 'constraints' => array(
  19. 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
  20. 'id' => '[0-9]+',
  21. ),
  22. 'defaults' => array(
  23. 'controller' => 'Creator\Controller\Index',
  24. 'action' => 'index',
  25. ),
  26.  
  27. ),
  28. 'may_terminate' => true,
  29. 'child_routes' => array(
  30. 'default' => array(
  31. 'type' => 'Segment',
  32. 'options' => array(
  33. 'route' => '/[:controller[/:action[/:id]]]',
  34. 'constraints' => array(
  35. 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
  36. 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
  37. 'id' => '[a-zA-Z0-9_-]*',
  38. ),
  39. 'defaults' => array(
  40. ),
  41. ),
  42. ),
  43. 'authUser' => array(
  44. 'type' => 'literal',
  45. 'options' => array(
  46. 'route' => '/authUser',
  47. 'defaults' => array(
  48. 'controller' => 'Creator\Controller\AuthUser',
  49. 'action' => 'index',
  50. )
  51. )
  52. )
  53. ),
  54. ),
  55. ),
  56. ),
  57.  
  58. 'view_manager' => array(
  59. 'template_path_stack' => array(
  60. 'creator' => __DIR__ . '/../view',
  61. ),
  62.  
  63. ),
  64. );
  65.  
  66. ?>
  67.  


src/Creator/Controller/IndexController.php
  1. <?php
  2. namespace Creator\Controller;
  3.  
  4. use Zend\Mvc\Controller\AbstractActionController;
  5. use Creator\Controller\AuthUserController;
  6. use Zend\Session\Container as SessionContainer;
  7.  
  8. class IndexController extends AbstractActionController
  9. {
  10. public function indexAction(){
  11. ini_set("display_errors", 1);
  12. $this->session = new SessionContainer('post_supply');
  13. // $this -> session->offsetSet('user', 'testUser');
  14. if ($this->session->offsetExists('user') === true){
  15. echo 'Istnieje sesja';
  16. }
  17. if ($this->session->offsetExists('user') !== true){
  18. $authUser = new AuthUserController;
  19. $authUser -> indexAction();
  20. echo ' Nie Istnieje sesja';
  21.  
  22. }
  23. }
  24. }


src/Creator/Controller/AuthUserContoller.php'
  1. <?php
  2. namespace Creator\Controller;
  3. use Zend\Mvc\Controller\AbstractActionController;
  4. use Zend\View\Model\ViewModel;
  5. use Zend\Authentication\Result;
  6. use Zend\Authentication\AuthenticationService;
  7. use Zend\Authentication\Storage\Session as SessionStorage;
  8. use Zend\Db\Adapter\Adapter as DbAdapter;
  9. use Zend\Authentication\Adapter\DbTable as AuthAdapter;
  10. use Creator\Model\AuthUser;
  11. use Creator\Form\AuthUserForm;
  12.  
  13. class AuthUserController extends AbstractActionController{
  14. public function indexAction(){
  15. echo $message = 'tes';
  16. $viewModel = new ViewModel(array(
  17. 'message' => $message,
  18. ));
  19. $viewModel->setTemplate('creator/authUser/index.phtml');
  20.  
  21. return $viewModel;
  22. }
  23. }