* control, so do not include passwords or other sensitive information in this
* file.
*/
-
return array(
- // ...
+ 'db' => array(
+ 'driver' => 'Pdo',
+ 'dsn' => 'sqlite:' . getcwd() . '/data/jeu_essai.db',
+ ),
+ /* Alternative
+ 'db' => array(
+ 'driver' => 'Pdo_Sqlite',
+ 'database' => getcwd() . '/data/jeu_essai.db',
+ ),*/
+ 'service_manager' => array(
+ 'factories' => array(
+ 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
+ ),
+ ),
);
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
+use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\EventManager\EventInterface;
use Zend\Mvc\ModuleRouteListener;
+use Galerie\Model\GalerieArrayTable;
+use Galerie\Model\GalerieATable;
+
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface,
- BootstrapListenerInterface
+ BootstrapListenerInterface,
+ ServiceProviderInterface
{
public function getAutoloaderConfig()
$e->getApplication()->getServiceManager()->get('translator');
}
+ public function getServiceConfig()
+ {
+ return array(
+ 'factories' => array(
+ 'Galerie\Model\GalerieArrayTable' => function($sm) {
+ return new GalerieArrayTable(
+ $sm->get('Zend\Db\Adapter\Adapter')
+ );
+ },
+ 'Galerie\Model\GalerieATable' => function($sm) {
+ return new GalerieATable(
+ $sm->get('Zend\Db\Adapter\Adapter')
+ );
+ },
+ ),
+ );
+ }
}
namespace Galerie\Controller;
use Zend\Mvc\Controller\AbstractActionController;
-
+use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
-{
+{
+
+ private $_galerieArrayTable;
+ private $_galerieATable;
+
+ private function _getGalerieArrayTable()
+ {
+ if (!$this->_galerieArrayTable) {
+ $sm = $this->getServiceLocator();
+ $this->_galerieArrayTable = $sm->get('Galerie\Model\GalerieArrayTable');
+ }
+ return $this->_galerieArrayTable;
+ }
+
+ private function _getGalerieATable()
+ {
+ if (!$this->_galerieATable) {
+ $sm = $this->getServiceLocator();
+ $this->_galerieATable = $sm->get('Galerie\Model\GalerieATable');
+ }
+ return $this->_galerieATable;
+ }
+
public function indexAction()
{
- return array();
+ return new ViewModel(array(
+ 'GalerieArray_all' => $this->_getGalerieArrayTable()->fetchAll(),
+ 'GalerieArray_one' => $this->_getGalerieArrayTable()->getGalerie(1),
+ 'GalerieA_all' => $this->_getGalerieATable()->fetchAll(),
+ 'GalerieA_one' => $this->_getGalerieATable()->getGalerie(1),
+ ));
}
public function editAction()
--- /dev/null
+<?php
+
+namespace Galerie\Model;
+
+class GalerieA
+{
+ public $id;
+ public $id_user;
+ public $name;
+ public $description;
+ public $created;
+ public $updated;
+
+ public function exchangeArray($data)
+ {
+ $this->id = isset($data['id']) ? $data['id'] : null;
+ $this->id_user = isset($data['is_user']) ? $data['id_user'] : null;
+ $this->name = isset($data['name']) ? $data['name'] : null;
+ $this->description = isset($data['description']) ? $data['description'] : null;
+ $this->created = isset($data['created']) ? $data['created'] : null;
+ $this->updated = isset($data['updated']) ? $data['updated'] : null;
+ }
+
+ public function toArray($data)
+ {
+ return array(
+ 'id' => $this->id,
+ 'is_user' => $this->id_user,
+ 'name' => $this->name,
+ 'description' => $this->description,
+ 'created' => $this->created,
+ 'updated' => $this->updated,
+ );
+ }
+
+}
--- /dev/null
+<?php
+namespace Galerie\Model;
+
+use Zend\Db\Adapter\Adapter;
+use Zend\Db\ResultSet\ResultSet;
+use Zend\Db\TableGateway\AbstractTableGateway;
+
+
+class GalerieATable extends AbstractTableGateway
+{
+ public $table = 'gallery';
+
+ public function __construct(Adapter $adapter)
+ {
+ // Composition avec l'adaptateur
+ $this->adapter = $adapter;
+
+ // Utilisation du patron de conception Prototype
+ // pour la création des objets ResultSet
+ $this->resultSetPrototype = new ResultSet();
+ $this->resultSetPrototype->setArrayObjectPrototype(
+ new GalerieA()
+ );
+
+ // Initialisation du gestionnaire
+ $this->initialize();
+ }
+
+ public function fetchAll()
+ {
+ return $this->select();
+ }
+
+ public function getGalerie($id)
+ {
+ if ($id === null) {
+ $row = null;
+ } else {
+ $row = $this->select(array(
+ 'id' => (int) $id,
+ ))->current();
+ }
+ if (!$row) {
+ throw new \Exception("cannot get row $id in table 'galerie'");
+ }
+ return $row;
+ }
+
+/* public saveGalerie(GalerieA $galerie)
+ {
+ if ($galerie->id === null) {
+ $this->insert(
+ array(
+ 'name' => $galerie->name,
+ 'description' => $galerie->description,
+ )
+ );
+ } elseif ($this->getGalerie($galerie->id)) {
+ $this->update(
+ array(
+ 'name' => $galerie->name,
+ 'description' => $galerie->description,
+ ),
+ array(
+ 'id' => $galerie->id,
+ )
+ );
+ } else {
+ throw new \Exception("cannot update row $galerie->id in table 'galerie'");
+ }
+ }
+*/
+ public function deleteGalerie($id)
+ {
+ $this->delete(array(
+ 'id' => (int) $id
+ )
+ );
+ }
+
+}
--- /dev/null
+<?php
+
+namespace Galerie\Model;
+
+class GalerieArray extends \ArrayObject
+{
+}
--- /dev/null
+<?php
+namespace Galerie\Model;
+
+use Zend\Db\Adapter\Adapter;
+use Zend\Db\ResultSet\ResultSet;
+use Zend\Db\TableGateway\AbstractTableGateway;
+
+
+class GalerieArrayTable extends AbstractTableGateway
+{
+ public $table = 'gallery';
+
+ public function __construct(Adapter $adapter)
+ {
+ // Composition avec l'adaptateur
+ $this->adapter = $adapter;
+
+ // Utilisation du patron de conception Prototype
+ // pour la création des objets ResultSet
+ $this->resultSetPrototype = new ResultSet();
+ $this->resultSetPrototype->setArrayObjectPrototype(
+ new GalerieArray()
+ );
+
+ // Initialisation du gestionnaire
+ $this->initialize();
+ }
+
+ public function fetchAll()
+ {
+ return $this->select();
+ }
+
+ public function getGalerie($id)
+ {
+ if ($id === null) {
+ $row = null;
+ } else {
+ $row = $this->select(array(
+ 'id' => (int) $id,
+ ))->current();
+ }
+ if (!$row) {
+ throw new \Exception("cannot get row $id in table 'galerie'");
+ }
+ return $row;
+ }
+
+/* public saveGalerie(GalerieA $galerie)
+ {
+ if ($galerie->id === null) {
+ $this->insert(
+ array(
+ 'name' => $galerie->name,
+ 'description' => $galerie->description,
+ )
+ );
+ } elseif ($this->getGalerie($galerie->id)) {
+ $this->update(
+ array(
+ 'name' => $galerie->name,
+ 'description' => $galerie->description,
+ ),
+ array(
+ 'id' => $galerie->id,
+ )
+ );
+ } else {
+ throw new \Exception("cannot update row $galerie->id in table 'galerie'");
+ }
+ }
+*/
+ public function deleteGalerie($id)
+ {
+ $this->delete(array(
+ 'id' => (int) $id
+ )
+ );
+ }
+
+}
--- /dev/null
+<?php
+namespace Galerie\Model
+
+use Zend\Db\Adapter\Adapter;
+use Zend\Db\ResultSet\ResultSet;
+use Zend\Db\TableGateway\AbstractTableGateway;
+
+class GalerieTableE extends AbstractTableGateway
+{
+ public $table = 'galerie';
+
+ public function __construct(Adapter $adapter)
+ {
+ // Composition avec l'adaptateur
+ $this->adapter = $adapter;
+
+ // Utilisation du patron de conception Prototype
+ // pour la création des objets ResultSet
+ $this->resultSetPrototype = new ResultSet();
+ $this->resultSetPrototype->setArrayObjectPrototype(
+ new Galerie()
+ );
+
+ // Initialisation du gestionnaire
+ $this->initialize();
+ }
+
+ public function fetchAll()
+ {
+ return $this->select();
+ }
+
+ public function getGalerie($id)
+ {
+ if ($id === null) {
+ $row = null;
+ } else {
+ $row = $this->select(array(
+ 'id' => (int) $id
+ ))->current();
+ }
+ if (!$row) {
+ throw new \Exception("cannot get row $id in table 'galerie'");
+ }
+ return $row;
+ }
+
+ public saveGalerie(Galerie $galerie)
+ {
+ if ($galerie->id === null) {
+ $this->insert(
+ $galerie->toUpdatableArray()
+ );
+ } elseif ($this->getGalerie($galerie->id)) {
+ $this->update(
+ $galerie->toUpdatableArray(),
+ $galerie->toPrimaryArray()
+ );
+ } else {
+ throw new \Exception("cannot update row $galerie->id in table 'galerie'");
+ }
+ }
+
+ public function deleteGalerie($id)
+ {
+ $this->delete(array(
+ 'id' => (int) $id
+ )
+ );
+ }
+
+}
<p>vue <em>back-office</em> d’une <strong>galerie</strong> : <?php echo $this->translate('index', 'galerie'); ?></p>
+
+<p>Affichage des galeries avec GalerieArray (test du fetchAll) :</p>
+
+<pre><?php echo $GalerieArray_all->count(); ?></pre>
+<pre><?php print_r($GalerieArray_all->toArray()); ?></pre>
+
+<p>Affichage d'une galerie avec GalerieArray (test du getGalerie) :</p>
+
+<pre><?php print_r($GalerieArray_one); ?></pre>
+<p>Identifiant : <?php echo $GalerieArray_one['id']; ?></p>
+
+
+
+
+<p>Affichage des galeries avec GalerieA (test du fetchAll) :</p>
+
+<pre><?php echo $GalerieA_all->count(); ?></pre>
+<pre><?php print_r($GalerieA_all->toArray()); ?></pre>
+
+<p>Affichage d'une galerie avec GalerieA (test du getGalerie) :</p>
+
+<pre><?php print_r($GalerieA_one); ?></pre>
+<p>Identifiant : <?php echo $GalerieA_one->id; ?></p>