From b1dab6b22674e442078ce69bcd4d2f0ca552dd82 Mon Sep 17 00:00:00 2001
From: Charles OLYMPIO <charles.olympio@ensiie.fr>
Date: Mon, 20 Nov 2017 00:38:55 +0100
Subject: [PATCH] Ajout des connexions au module User et correction du routing

---
 .../module/User/config/module.config.php          | 15 +++++++++++++++
 .../User/src/Controller/ConnexionController.php   |  6 +++---
 .../module/User/src/Model/ConnexionTable.php      |  2 +-
 .../module/User/src/Module.php                    | 15 +++++++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/ZendSkeletonApplication-master/module/User/config/module.config.php b/ZendSkeletonApplication-master/module/User/config/module.config.php
index 04997a7..91f7f97 100644
--- a/ZendSkeletonApplication-master/module/User/config/module.config.php
+++ b/ZendSkeletonApplication-master/module/User/config/module.config.php
@@ -21,11 +21,26 @@ return [
                     ],
                 ],
             ],
+            'connexion' => [
+                'type'    => Segment::class,
+                'options' => [
+                    'route' => '/connexion[/:action[/:id]]',
+                    'constraints' => [
+                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
+                        'id'     => '[0-9]+',
+                    ],
+                    'defaults' => [
+                        'controller' => Controller\ConnexionController::class,
+                        'action'     => 'index',
+                    ],
+                ],
+            ],
         ],
     ],
     'view_manager' => [
         'template_path_stack' => [
             'user' => __DIR__ . '/../view',
+            'connexion' => __DIR__ . '/../view',
         ],
     ],
 ]; ?>
diff --git a/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php b/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php
index 9cdefc8..1cf501d 100644
--- a/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php
+++ b/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php
@@ -1,11 +1,11 @@
 <?php
 namespace User\Controller;
 
-use User\Model\UserTable;
+use User\Model\ConnexionTable;
 use Zend\Mvc\Controller\AbstractActionController;
 use Zend\View\Model\ViewModel;
 
-class UserController extends AbstractActionController
+class ConnexionController extends AbstractActionController
 {
   // Add this property:
     private $table;
@@ -19,7 +19,7 @@ class UserController extends AbstractActionController
     public function indexAction()
     {
       return new ViewModel([
-            'users' => $this->table->fetchAll(),
+            'connexions' => $this->table->fetchAll(),
         ]);
     }
 
diff --git a/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php b/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php
index a3439d7..caf0835 100644
--- a/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php
+++ b/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php
@@ -1,5 +1,5 @@
 <?php
-namespace Connexion\Model;
+namespace User\Model;
 
 use RuntimeException;
 use Zend\Db\TableGateway\TableGatewayInterface;
diff --git a/ZendSkeletonApplication-master/module/User/src/Module.php b/ZendSkeletonApplication-master/module/User/src/Module.php
index bbce033..f415092 100644
--- a/ZendSkeletonApplication-master/module/User/src/Module.php
+++ b/ZendSkeletonApplication-master/module/User/src/Module.php
@@ -27,6 +27,16 @@ class Module implements ConfigProviderInterface
                     $resultSetPrototype->setArrayObjectPrototype(new Model\User());
                     return new TableGateway('users', $dbAdapter, null, $resultSetPrototype);
                 },
+                Model\ConnexionTable::class => function($container) {
+                    $tableGateway = $container->get(Model\ConnexionTableGateway::class);
+                    return new Model\ConnexionTable($tableGateway);
+                },
+                Model\ConnexionTableGateway::class => function ($container) {
+                    $dbAdapter = $container->get(AdapterInterface::class);
+                    $resultSetPrototype = new ResultSet();
+                    $resultSetPrototype->setArrayObjectPrototype(new Model\Connexion());
+                    return new TableGateway('connexions', $dbAdapter, null, $resultSetPrototype);
+                },
             ],
         ];
     }
@@ -40,6 +50,11 @@ class Module implements ConfigProviderInterface
                         $container->get(Model\UserTable::class)
                     );
                 },
+                Controller\ConnexionController::class => function($container) {
+                    return new Controller\ConnexionController(
+                        $container->get(Model\ConnexionTable::class)
+                    );
+                },
             ],
         ];
     }
-- 
GitLab