title: Zend Framework 2 request
body: <p>I have a problem to request select in where condition:</p>
  
  <p>Notice: Undefined variable: idSous in
  C:\wamp\www\zf2\module\Categorie\src\Categorie\Model\CategorieTable.php
  on line 26</p>
  
  <pre><code>&lt;?php
  namespace Categorie\Model;
  
  use Zend\Db\TableGateway\TableGateway;
  use Zend\Db\Sql\Select;
  
  class CategorieTable
  {    
      protected $tableGateway;
  
      public function __construct(TableGateway $tableGateway)
      {
          $this-&gt;tableGateway = $tableGateway;
      }
  
      //fonction qui permet d'afficher tous la table "Article" 
      public function fetchAll($idSous)
      {   
  
          $idSous  = (int) $idSous;
          $resultSet = $this-&gt;tableGateway-&gt;select(function (Select $select) {
          $select-&gt;columns(array('titre_art', 'description_art'))
          -&gt;join('sous_categorie', 'articles.id_sous_categorie = sous_categorie.id_sous_categorie')
          -&gt;where-&gt;like('sous_categorie.id_sous_categorie', $idSous);
          });
          return $resultSet;
      }
  
  }
  </code></pre>
  
  <p>but when I use this requet it's run :</p>
  
  <pre><code>&lt;?php
  namespace Categorie\Model;
  
  use Zend\Db\TableGateway\TableGateway;
  use Zend\Db\Sql\Select;
  
  class CategorieTable
  {    
      protected $tableGateway;
  
      public function __construct(TableGateway $tableGateway)
      {
          $this-&gt;tableGateway = $tableGateway;
      }
  
      public function fetchAll($idSous) {
          $idSous  = (int) $idSous;
          $resultSet = $this-&gt;tableGateway-&gt;select("id_sous_categorie = $idSous");
          var_dump($resultSet);
          return $resultSet;
      }
  }
  </code></pre>
  
  <p>Why is my second request run but not the first?</p>
  
  <p>I need get the $idSous in this controller</p>
  
  <pre><code>&lt;?php
  namespace Categorie\Controller;
  
  use Zend\Mvc\Controller\AbstractActionController;
  use Zend\View\Model\ViewModel;
  
  class AgroalimentaireController extends AbstractActionController
  {   
      protected $categorieTable;
  
      public function indexAction($idSous = 2)
      {
          return new ViewModel(array(
              'categorie' =&gt; $this-&gt;getAnnoncesTable()-&gt;fetchAll($idSous),
          ));
      }
  
      public function getAnnoncesTable()
      {   
          //permet de recupéré les champs de la table "Article"
          if (!$this-&gt;categorieTable) {
              $sm = $this-&gt;getServiceLocator();
              $this-&gt;categorieTable = $sm-&gt;get('Categorie\Model\CategorieTable');
          }
          return $this-&gt;categorieTable;
      }
  }
  </code></pre>