Ciao, ho visto un po' di esempi sull'utilizzo corretto dell'MVC con Zend, come ad esempio il quickstart
nella mia applicazione ho qualche cosa tipo (per quanto riguarda il Model):
quindi con un file gestisco tutte le operazioni sul DB, per esempio della tabella utenti (Users)
codice:
<?php
class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract {
public function getUser($id) {
$id = (int)$id;
$row = $this->fetchRow('userId = ' . $id);
if (!$row) {
throw new Exception("Could not find row");
}
return $row->toArray();
}
...
in molti esempi on line (come quickstart) vedo invece che viene applicata questa soluzione
DbTable contiene solo
codice:
<?php
class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract
{
protected $_name = 'guestbook';
}
mentre tutto è gestito da
codice:
<?php
class Application_Model_Guestbook
{
protected $_comment;
protected $_created;
protected $_email;
protected $_id;
public function __construct(array $options = null)
{
if (is_array($options)) {
$this->setOptions($options);
}
}
....
e da un mapper
codice:
<?php
class Application_Model_GuestbookMapper
{
protected $_dbTable;
public function setDbTable($dbTable)
{
if (is_string($dbTable)) {
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
Che differenza c'è?
Grazie