Or any infrastructure for that matter.
Using Zend Framework 2 as an example, I have the following table class:
<?php namespace Contact\Model; use Zend\Db\TableGateway\TableGateway; use Zend\Db\TableGateway\AbstractTableGateway; use Zend\Log\Logger; class UserContactsTable extends AbstractTableGateway { protected $tableGateway; protected $logger; public function __construct(TableGateway $tableGateway, Logger $logger ) { $this->tableGateway = $tableGateway; $this->logger = $logger; } public function saveUserContact(UserContact $userContact) { $data = array( 'user_id' => $userContact->user_id, 'contact_id' => $userContact->contact_id ); try { $this->tableGateway->insert($data); } catch (\Exception $e) {
Do I have to register here? Should I associate my logger with a table class? Should I let saveUserContact function throw an exception if the insert fails and gets caught in the controller and logs there?
What are the best practices?
My initial idea was to create a class with some persistent error messages, such as insert and update errors, which the registrar will use in the table class, but I'm not sure if this is the right process.
Actually this is not limited to PHP or Zend Framework 2, but it happens that this is the language that I use.
source share