{"id":1250,"date":"2022-08-30T15:14:53","date_gmt":"2022-08-30T15:14:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/set-parameter-with-tablegateway-select-function-show-error-undefined-variable-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:14:53","modified_gmt":"2022-08-30T15:14:53","slug":"set-parameter-with-tablegateway-select-function-show-error-undefined-variable-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/set-parameter-with-tablegateway-select-function-show-error-undefined-variable-collection-of-common-programming-errors\/","title":{"rendered":"Set Parameter with TableGateway Select Function show error undefined variable-Collection of common programming errors"},"content":{"rendered":"<p>i create a function in my model like :<\/p>\n<pre><code>public function getAllMenuByOnlyActionPage($actionlot){\n\n            $act  = trim($actionlot);\n            $result = $this-&gt;tableGateway-&gt;select(function (Select $select) {\n                        $select-&gt;where(array('status != ?' =&gt; 13))\n                        -&gt;where(array('action' =&gt; $act))\n                        -&gt;order('id ASC');\n                    }); \n            $results = array();\n            foreach ($result as $row) {\n                $results[] = $row;\n            }\n            return $results;\n\n        }  \n<\/code><\/pre>\n<p>When i try to execute then its show me <code>Notice: Undefined variable: act<\/code>. I already see this link ZF2 tableGateway select but i want to set parameter for this function. Thanks<\/p>\n<ol>\n<li>\n<p>Try<\/p>\n<pre><code>$result = $this-&gt;tableGateway-&gt;select(function (Select $select) use ($act)  {\n                        $select-&gt;where(array('status != ?' =&gt; 13))\n                        -&gt;where(array('action' =&gt; $act))\n                        -&gt;order('id ASC');\n                    }); \n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:12:10. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>i create a function in my model like : public function getAllMenuByOnlyActionPage($actionlot){ $act = trim($actionlot); $result = $this-&gt;tableGateway-&gt;select(function (Select $select) { $select-&gt;where(array(&#8216;status != ?&#8217; =&gt; 13)) -&gt;where(array(&#8216;action&#8217; =&gt; $act)) -&gt;order(&#8216;id ASC&#8217;); }); $results = array(); foreach ($result as $row) { $results[] = $row; } return $results; } When i try to execute then its show [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1250","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1250"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1250\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}