Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

8. vederea inregistrarilor

57 views

Published on

http://www.rraducanu.ro

Published in: Education
  • Be the first to comment

  • Be the first to like this

8. vederea inregistrarilor

  1. 1. Vederea inregistrarilor
  2. 2. Creati modulul Data: si apoi efectuati toate configurarile necesare.
  3. 3. config/autoload/global.php return [ 'db'=>[ 'driver'=>'Pdo', 'dsn'=>'mysql:dbname=flowers;host=localhost;charset=utf8', 'username'=>'root', 'password'=>'' ] ];
  4. 4. Pentru a gestiona baze de date va trebui sa cream un model. Pentru aceasta, vom crea directorul: Module/database/src/Model si in acesta fisierele Flower.php si FlowerTable.php
  5. 5. Flower.php <?php namespace DataModel; class Flower { protected $id; protected $nume; protected $culoare; protected $marime; protected $pret; public function exchangeArray(array $data) { $this->id=$data['id']; $this->nume=$data['nume']; $this->culoare=$data['culoare']; $this->marime=$data['marime']; $this->pret=$data['pret']; }
  6. 6. public function getArrayCopy() { return [ 'id'=>$this->id, 'nume'=>$this->nume, 'culoare'=>$this->culoare, 'marime'=>$this->marime, 'pret'=>$this->pret ]; } public function getId() { return $this->id; } public function getNume() { return $this->nume; } public function getCuloare() { return $this->culoare; }
  7. 7. public function getMarime() { return $this->marime; } public function getPret() { return $this->pret; } }
  8. 8. FlowerTable.php <?php namespace DataModel; use ZendDbTableGatewayTableGatewayInterface; class FlowerTable { protected $tableGateway; public function __construct(TableGatewayInterface $tableGateway) { $this->tableGateway=$tableGateway; } public function fetchAll() { return $this->tableGateway->select(); }
  9. 9. module/Database/src/Module.php <?php namespace Data; use ZendDbAdapterAdapterInterface; use ZendDbTableGatewayTableGateway; use ZendDbResultSetResultSet; use ZendModuleManagerFeatureConfigProviderInterface; class Module implements ConfigProviderInterface { const VERSION = '3.0.3-dev'; public function getConfig() { return include __DIR__ . '/../config/module.config.php'; }
  10. 10. public function getServiceConfig() { return [ 'factories'=>[ ModelFlowerTable::class=>function($container){ $tableGateway=$container- >get(ModelFlowerTableGateway::class); return new ModelFlowerTable($tableGateway); }, ModelFlowerTableGateway::class=>function($container){ $adapter=$container->get(AdapterInterface::class); $resultSetPrototype=new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new ModelFlower); return new TableGateway('flower',$adapter,null,$resultSetPrototype); } ] ]; }
  11. 11. public function getControllerConfig() { return[ 'factories'=>[ ControllerIndexController::class=>function($container) { return new ControllerIndexController( $container->get(ModelFlowerTable::class) ); } ] ]; } }
  12. 12. IndexController namespace DataController; use ZendMvcControllerAbstractActionController; use ZendViewModelViewModel; class IndexController extends AbstractActionController { protected $table; public function __construct($table) { $this->table=$table; } public function indexAction() { $flower=$this->table->fetchAll(); return new ViewModel(array('flower'=>$flower)); }
  13. 13. Data/config/module.config.php Comentati linia: 'controllers' => [ 'factories' => [ // ControllerIndexController::class => InvokableFactory::class, ], ],
  14. 14. view/data/index/index.phtml <table> <tr> <th style="width:100px">Nume</th> <th style="width:100px">Culoare</th> <th style="width:100px">Marime</th> <th style="width:100px">Pret</th> <th style="width:100px" colspan="3" align="center">Actions</th> </tr> <?php foreach($flower as $var){ ?> <tr> <td><?php echo $var->GetNume();?></td> <td><?php echo $var->GetCuloare();?></td> <td><?php echo $var->GetMarime();?></td> <td><?php echo $var->GetPret();?></td>
  15. 15. <td> <a href="<?php echo $this->url('data',['action'=>'view','id'=>$var->getId()]); ?>">View</a> <a href="<?php echo $this->url('data',['action'=>'edit','id'=>$var->getId()]); ?>">Edit</a> <a href="<?php echo $this->url('data',['action'=>'delete','id'=>$var->getId()]); ?>">Delete</a> </td> </tr> <?php } ?> </table> <br/><br/> <a href="/add">Add another record</a>

×