{"id":513,"date":"2022-08-30T15:02:36","date_gmt":"2022-08-30T15:02:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/joomla-2-5-getuserstatefromrequest-load-error-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:36","modified_gmt":"2022-08-30T15:02:36","slug":"joomla-2-5-getuserstatefromrequest-load-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/joomla-2-5-getuserstatefromrequest-load-error-collection-of-common-programming-errors\/","title":{"rendered":"Joomla 2.5 getUserStateFromRequest load error-Collection of common programming errors"},"content":{"rendered":"<p>I was following the example to implement custom filters in Joomla 2.5 admin component.<\/p>\n<p>But I am getting error at models <code>populateState<\/code> method:<\/p>\n<blockquote>\n<p>Call to undefined method somecompModelsomecomp::getUserStateFromRequest().<\/p>\n<\/blockquote>\n<pre><code>$app = JFactory::getApplication('administrator');\n\/\/ Load the filter state.\n$search = $this-&gt;getUserStateFromRequest($this-&gt;context.'.filter.search', 'filter_search');\n<\/code><\/pre>\n<p>Error disappears if I call <code>getUserStateFromRequest<\/code> using <code>$app<\/code>:<\/p>\n<pre><code>$app-&gt;getUserStateFromRequest($this-&gt;context.'.filter.search', 'filter_search');\n<\/code><\/pre>\n<p>So whats the problem? In default Joomla components I&#8217;ve seen that it use the same approach and it works. Maybe I miss something in my model class?<\/p>\n<p>Any ideas?<\/p>\n<ol>\n<li>\n<p>This is happened because <code>$app<\/code> is an object of your application class. As you defined it in your code.<\/p>\n<p><code>$app = JFactory::getApplication('administrator');<\/code><\/p>\n<p>and <code>getUserStateFromRequest<\/code> method is defind in that Application class.so you have to use it like this if you want to access this method.<\/p>\n<pre><code>$app-&gt;getUserStateFromRequest($this-&gt;context.'.filter.search', 'filter_search');\n<\/code><\/pre>\n<p>And for your information <code>$this<\/code> variable is your local object.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:02:44. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I was following the example to implement custom filters in Joomla 2.5 admin component. But I am getting error at models populateState method: Call to undefined method somecompModelsomecomp::getUserStateFromRequest(). $app = JFactory::getApplication(&#8216;administrator&#8217;); \/\/ Load the filter state. $search = $this-&gt;getUserStateFromRequest($this-&gt;context.&#8217;.filter.search&#8217;, &#8216;filter_search&#8217;); Error disappears if I call getUserStateFromRequest using $app: $app-&gt;getUserStateFromRequest($this-&gt;context.&#8217;.filter.search&#8217;, &#8216;filter_search&#8217;); So whats the problem? In [&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-513","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/513","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=513"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/513\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}