title: Zend Framework - How to resolve catchable fatal error on argument 1 of model constructor invocation?
body: <p><strong>Scenario:</strong></p>
  
  <p>After setting up the Zend Framework Latest Skeleton App and setting up debugging in my local PHP Debugger Tool Eclipse environment,  I have come across an issue while setting up my first model, called ActionItem.  As per the instructions on Zend Framework I have included getServiceConfig() in my Module.php.</p>
  
  <p><strong>Specific Error</strong> </p>
  
  <blockquote>
    <p>Catchable fatal error: Argument 1 passed to Application\Model\ActionItem::__construct() must be an instance of Zend\Db\TableGateway\TableGateway, none given</p>
  </blockquote>
  
  <p><strong>Analysis:</strong></p>
  
  <p>In the code below (<strong><em>Module.php</em></strong>), my ActionItem() constructor (in 3rd code block <strong>Model.php</strong>) has no argument passed to it as a TableGateway argument.  </p>
  
  <p><strong>Module.php</strong></p>
  
  <pre><code> public function getServiceConfig()
          {   
               return array(
                   'factories' =&gt; array(
                       'Application\Model\ActionItem' =&gt;  function($sm) {
                           $tableGateway = $sm-&gt;get('ActionItemTableGateway');
                           $table = new ActionItem($tableGateway);
                           return $table;
                       },
                       'ActionItemTableGateway' =&gt; function ($sm) {
                           $dbAdapter = $sm-&gt;get('Zend\Db\Adapter\Adapter');
                           $resultSetPrototype = new ResultSet();
                           $resultSetPrototype-&gt;setArrayObjectPrototype(new ActionItem());  ###### Here, the ActionItem Constructor is passed nothing causing the fatal error.
                           return new TableGateway('application', $dbAdapter, null, $resultSetPrototype);
                       },
                   ),
               );
          }
  </code></pre>
  
  <p><strong>Controller</strong>
  SummaryController.php </p>
  
  <pre><code>namespace Application\Controller;
  
  use Application\Model\ActionItem;
  use Zend\Mvc\Controller\AbstractActionController;
  use Zend\View\Model\ViewModel;
  
  class SummaryController extends AbstractActionController
  {
      protected $actionItem;
  
      public function getActionItem()
      {
          if (!$this-&gt;actionItem) {
              $sm = $this-&gt;getServiceLocator();
              $this-&gt;actionItem = $sm-&gt;get('Application\Model\ActionItem');
          }
          return $this-&gt;actionItem;
      }
  
      public function IndexAction()
      {
          return new ViewModel(array (
              'actionitems' =&gt; $this-&gt;getActionItem()-&gt;fetchAll(),    
          ));
          //return new ViewModel();
      }
  }
  </code></pre>
  
  <p><strong>Model</strong>  ActionItem.php</p>
  
  <pre><code>namespace Application\Model;
  
      use Zend\Db\TableGateway\TableGateway;
  
      class ActionItem {
          protected $tableGateway;
  
          public function __construct(TableGateway $tableGateway)
          {
              $this-&gt;tableGateway = $tableGateway;
          }
  
          public function fetchAll()
          {
              $resultSet = $this-&gt;tableGateway-&gt;select();
              return $resultSet;
          }
  
      }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Is there a single way to resolve this, or can I take several approaches?  What can I do to resolve the error?</p>
  
  <p>Thank you.</p>