2013-03-21 25 views
1

我在我的模型,如創建一個函數:設置參數與TableGateway選擇功能顯示錯誤未定義的變量

public function getAllMenuByOnlyActionPage($actionlot){ 

      $act = trim($actionlot); 
      $result = $this->tableGateway->select(function (Select $select) { 
         $select->where(array('status != ?' => 13)) 
         ->where(array('action' => $act)) 
         ->order('id ASC'); 
        }); 
      $results = array(); 
      foreach ($result as $row) { 
       $results[] = $row; 
      } 
      return $results; 

     } 

當我嘗試執行那麼它告訴我Notice: Undefined variable: act。我已經看到這個鏈接ZF2 tableGateway select,但我想爲此功能設置參數。由於

回答

9

嘗試

$result = $this->tableGateway->select(function (Select $select) use ($act) { 
         $select->where(array('status != ?' => 13)) 
         ->where(array('action' => $act)) 
         ->order('id ASC'); 
        }); 
+0

感謝,如果你有這樣的參考鏈接,請給我聯繫它的工作原理。 – imsyedahmed 2013-03-21 07:43:31